Announcement

Collapse
No announcement yet.

Randomizing users

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Randomizing users

    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?
    Famous quote about Arson from Arson: "As for the reasoning: I did it because I could. Does that make me an *******? Indeed. He should learn to implement more security into his files, and maybe it wouldn't happen."

  • #2
    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.
    [tabmenu]
    [tab='McCode Mods - 2 Player Live Games']
    $15-$75
    [mp]198[/mp]
    [/tabmenu]

    Comment


    • #3
      Re: Randomizing users

      Originally posted by seanybob
      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.
      Famous quote about Arson from Arson: "As for the reasoning: I did it because I could. Does that make me an *******? Indeed. He should learn to implement more security into his files, and maybe it wouldn't happen."

      Comment


      • #4
        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

        Comment


        • #5
          Re: Randomizing users

          Well I'll be darned.* That does work!!!
          Famous quote about Arson from Arson: "As for the reasoning: I did it because I could. Does that make me an *******? Indeed. He should learn to implement more security into his files, and maybe it wouldn't happen."

          Comment


          • #6
            Re: Randomizing users

            Comment


            • #7
              Re: Randomizing users

              Originally posted by Decepti0n
              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*
              [tabmenu]
              [tab='McCode Mods - 2 Player Live Games']
              $15-$75
              [mp]198[/mp]
              [/tabmenu]

              Comment


              • #8
                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.

                Comment


                • #9
                  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!
                  Anthony - Magictallguy - Website developer, computer technician and professional musician
                  My Repo

                  Comment


                  • #10
                    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]
                    Need a mod for your game? I do work that is second to none. PM me for further details or click on my banner to view my website.

                    Comment


                    • #11
                      Re: Randomizing users

                      Originally posted by Floydian
                      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
                      [progressbar=35,#202020,#ff0000]Imperium Wars[/progressbar]

                      Comment

                      Working...
                      X