Raised This Month: $ Target: $400
 0% 

Setting an unique value to each cell of an array.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-25-2010 , 10:50   Re: Setting an unique value to each cell of an array.
Reply With Quote #1

try this:
PHP Code:
public cmdPrint(id)
{
    for(new 
i=0SIZEi++)
    {
        var[
i] = i+1
    
}
    new 
tmprand
    
for(new i=0SIZE-1i++)
    {
        
rand i+random(SIZE-i)

        
tmp = var[i]
        var[
i] = var[rand]
        var[
rand] = tmp       
    
}
    for(new 
i=0SIZEi++)
    {
        
client_print(idprint_console"var[%d]: %d"i, var[i])
    }

__________________
Impossible is Nothing
Sylwester is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-25-2010 , 14:07   Re: Setting an unique value to each cell of an array.
Reply With Quote #2

Code:
public cmdPrint(id) {     new tmp[SIZE];     for(new i = 0; i < SIZE; i++)     {         tmp[i] = i + 1;     }     new rand, tsize = SIZE;     for(new i = 0; i < SIZE; i++)     {         rand = random(tsize);         var[i] = tmp[rand];         tmp[rand] = tmp[--tsize];         client_print(id, print_console, "Number: %d", var[i]);     } }
or
Code:
public cmdPrint(id) {     for(new i = 0; i < SIZE; i++)     {         var[i] = i + 1;     }         SortCustom1D(var, SIZE, "SortRandomVars");         for(new i = 0; i < SIZE; i++)     {         client_print(id, print_console, "Number: %d", var[i]);     } } public SortRandomVars(elem1, elem2, array[], data[], size) {     return clamp(random_num(-50, 50), -1, 1); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Reply



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 11:16.


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