UCC Posted February 28, 2007 Posted February 28, 2007 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? Quote
seanybob Posted February 28, 2007 Posted February 28, 2007 Re: Randomizing users 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. Quote
UCC Posted February 28, 2007 Author Posted February 28, 2007 Re: Randomizing users 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. Quote
Decepti0n Posted February 28, 2007 Posted February 28, 2007 Re: Randomizing users 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 Quote
UCC Posted February 28, 2007 Author Posted February 28, 2007 Re: Randomizing users Well I'll be darned. That does work!!! Quote
seanybob Posted March 2, 2007 Posted March 2, 2007 Re: Randomizing users 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* Quote
stryker Posted May 15, 2007 Posted May 15, 2007 Re: Randomizing users 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. Quote
Magictallguy Posted February 13, 2008 Posted February 13, 2008 Re: Randomizing users yet again, deception proves his genius, using one line of code for every 20 of mine *smacks him* Hahaha! That's brilliant! Quote
Floydian Posted February 13, 2008 Posted February 13, 2008 Re: Randomizing users order by rand(), I would have thought it more complicated than that. That's very good to know! [me=Floydian]gets busy right away trying to figure out where he can use order by rand().[/me] Quote
General Doom Posted February 19, 2008 Posted February 19, 2008 Re: Randomizing users order by rand(), I would have thought it more complicated than that. That's very good to know! [me=Floydian]gets busy right away trying to figure out where he can use order by rand().[/me] Yeah I did the same. Went through some of my gameslooking for anything I could use it in. :P Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.