Raised This Month: $12 Target: $400
 3% 

Randomize an array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sputnik53
Senior Member
Join Date: Jun 2005
Old 08-19-2011 , 12:08   Randomize an array
Reply With Quote #1

Is there a quick and painless way to randomize an array? I'm taking the normal player array of alive players and want to do things to them in a random order.

I actually have a few other array related questions aswell (since they seem like black magic to me).

#2: How do I set a 2 dimensional array with strings, like
"blabla" "xd"
"buuhoo" "xp"
and then retrive the second string by searching with the first one.

#3: How do I sort the list of alive players by health for example?

Sorry I'm such a noob, can't find proper answers by searching.

Last edited by Sputnik53; 08-19-2011 at 12:20.
Sputnik53 is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 08-19-2011 , 12:19   Re: Randomize an array
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=74666
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-19-2011 , 13:58   Re: Randomize an array
Reply With Quote #3

2. Loop through the array until the keys match, then get the 2nd string.
I can't really help more without seeing a real use/example.

3. SortCustom1D()
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Sputnik53
Senior Member
Join Date: Jun 2005
Old 08-19-2011 , 14:43   Re: Randomize an array
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
2. Loop through the array until the keys match, then get the 2nd string.
I can't really help more without seeing a real use/example.
I want to rename a few players with an array that has the player names and their replacement names set.
Quote:
Originally Posted by Exolent[jNr] View Post
What does the extra data part do in this function? Perhaps you could give an example on how to sort players by their health.

Last edited by Sputnik53; 08-19-2011 at 15:11.
Sputnik53 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-19-2011 , 16:25   Re: Randomize an array
Reply With Quote #5

2. Your best method would be to use a Trie for storing by keys.

3. I'll show you an example of some other sorting so you can learn how it works.

Code:
// lets sort these lowest to highest new values[] = {1, 6, 2, 10, 5, 3, 6}; // call sort function SortCustom1D(values, sizeof(values), "SortValues"); // result: //values[] = {1, 2, 3, 5, 6, 6, 10} // .. public SortValues(value1, value2, array[], data[], dataSize) {     // value1 and value2 are the values from the array, not indexes         // remember, sorting with lowest first     if(value1 < value2) {         // value1 is lower, so return -1 showing that it goes before value2         return -1;     }     else if(value1 > value2) {         // value2 is lower, so return 1 showing that it goes before value1         return 1;     }         // values are equal, so return 0 showing there was no difference     return 0; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Old 08-20-2011, 06:18
jansonbaby51
This message has been deleted by xPaw. Reason: Spam.
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 16:11.


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