Raised This Month: $ Target: $400
 0% 

Creating random array


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-17-2008 , 09:19   Re: Creating random array
Reply With Quote #3

I hope I understand well what you need. Your array will be filled with random value from 0 to 25. I prefer using another array since it's more fast and easy to do. Another method without using temporary array would be to fill the original array with -1 ( for example ) and each time checking the whole array if the random value is used or not.

Code:
    #include <amxmodx>         public plugin_init ()     {         new MyArray  [ 26 ] = { 0, 1, ... }; // --| Your array { 0, 1, 2, etc.. }         new ArrayTemp[ 26 ];                 new i_Rand;                 for ( new i; i < 26; i++ )         {             i_Rand = random_num ( 0, 25 );                         if ( !ArrayTemp[ i_Rand ] )  // --| This random value is not used             {                 MyArray[ i ] = i_Rand;                 ArrayTemp[ i_Rand ] = 1; // --| This random value is now locked.             }             else // --| This random value is already used, need to try another value             {                 --i;             }         }         // --| Results         for ( new i; i < 26; i++ )         {             log_amx ( "i = %d", MyArray[ i ] );         }     }
__________________
Arkshine is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:08.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode