PDA

View Full Version : Randomizing users



UCC
02-28-2007, 08:47 PM
So I have a new gang mod. Without going into boring details, Gang A can cause negative affect to Gang B. However, Gang A may have 3 members where Gang B has 20 members. It's not fair that Gang A can cause more carnage than Gang B due to the difference in member counts.

I could do something like

Select * from users where Gang = Gang B LIMIT 3

However.... Every time Gang A attacked, the same 3 members of Gang B would be harmed. (the first 3 user_ids.

How can I randomize which 3 gang user records are pulled in my query?

seanybob
02-28-2007, 09:07 PM
My first thought would be to make an array with each of the user's ID, then do a rand from 1 to the largest value in the array, and do that 3 times or something like that... When I get home I'll give it a shot.

UCC
02-28-2007, 09:15 PM
My first thought would be to make an array with each of the user's ID, then do a rand from 1 to the largest value in the array, and do that 3 times or something like that... When I get home I'll give it a shot.


Hey, that does sound like a good idea!* I'm not that familiar with PHP arrays.* Any sample code you could throw at me would be useful.* Even something real basic (3-5 lines) would help.

Create array from : Select userid from users
Pick random userid from array
Print userid

I could take it from there.

Decepti0n
02-28-2007, 09:21 PM
Select * from users where Gang = Gang B ORDER BY RAND() LIMIT 3

thats to order it randomly, i didn't really understand the question though XD

UCC
02-28-2007, 09:25 PM
Well I'll be darned.* That does work!!!

Decepti0n
02-28-2007, 09:30 PM
;)

seanybob
03-02-2007, 06:23 AM
Select * from users where Gang = Gang B ORDER BY RAND() LIMIT 3

thats to order it randomly, i didn't really understand the question though XD


yet again, deception proves his genius, using one line of code for every 20 of mine *smacks him*

stryker
05-15-2007, 04:30 PM
sometimes the best way to go about doing things is to simplify your code. i say this because a function should not be 300 lines of code maybe 5 or 10 lines.

Magictallguy
02-13-2008, 03:56 PM
yet again, deception proves his genius, using one line of code for every 20 of mine *smacks him*


Hahaha! That's brilliant!

Floydian
02-13-2008, 08:19 PM
order by rand(), I would have thought it more complicated than that.

That's very good to know!
gets busy right away trying to figure out where he can use order by rand().

General Doom
02-19-2008, 03:29 PM
order by rand(), I would have thought it more complicated than that.

That's very good to know!
gets busy right away trying to figure out where he can use order by rand().


Yeah I did the same. Went through some of my gameslooking for anything I could use it in. :P