MakeWebGames

# Randomizing users

## Recommended Posts

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?

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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

##### Share on other sites

Re: Randomizing users

Well I'll be darned.  That does work!!!

##### Share on other sites

Re: Randomizing users

;)

##### Share on other sites

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*

##### Share on other sites

• 2 months later...

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.

##### Share on other sites

• 8 months later...

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!

##### Share on other sites

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]

##### Share on other sites

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

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• #### Marketplace

• Discord Chat
• PBBG Directory
×
• Create New...