1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Let your favorite entries duke it out in the 15th Techtree Contest Poll.
    Dismiss Notice
  4. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Snippet] Random Seed

Discussion in 'Graveyard' started by Nestharus, Jan 16, 2012.

  1. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Tired of having random numbers that are the same for each game, so I dev'd this to change it up. The only way they will be the same now is if the players do things at the same exact instant >: P.

    Code (vJASS):

    library RandomNumber
        globals
            private integer seconds = 0
            private timer t
        endglobals
        function UpdateSeed takes nothing returns nothing
            call SetRandomSeed(R2I((seconds+TimerGetElapsed(t))*1000)+GetRandomInt(-2147483648, 2147483647))
        endfunction
        private module Init
            private static method inc takes nothing returns nothing
                set seconds = seconds + 1
            endmethod
            private static method onInit takes nothing returns nothing
                set t = CreateTimer()
                call TimerStart(t, 1, true, function thistype.inc)
            endmethod
        endmodule
        private struct Inits extends array
            implement Init
        endstruct
    endlibrary
     



    Essentially, update random seed every time you are getting something random and you will ensure very unique randomness : O.
     
  2. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    469
    Resources:
    0
    Resources:
    0
    Are you aware of File -> Preferences -> Test Map -> Checkbox "Use Fixed Random Seed"?
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    This'll still ensure more unique games as the randomness is based on the players : ).
     
  4. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,003
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Isn't it already random enough? :/
    When a player loses or wins, SetRandomSeed(GetRandomInt(0, 1000000)) is called.
     
  5. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    A lot of games have randomness at the very, very start of the match (random heroes or races). Thus, the random seed can be set based on a player action, when -ar is typed, or when -random is typed ; P. Heck, you could have the random seed update every time a player does anything =o.
     
  6. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,003
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    That's actually a pretty cool idea.
    I approve. I wonder what Bribe thinks :x
     
  7. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    469
    Resources:
    0
    Resources:
    0
    That does not make any sense. You already have random numbers. And those numbers are random for you if you don't know the initial seed.

    And why would someone bother to reverse the seed? To crack our certificates we generate in wc3 (haha)? There is no need for a real number random generator. We don't do our crypto in wc3… And the normal way is sufficient enough.

    So what's the difference between
    UpdateSeed();ChooseHero(GetRandomInt(0, num_heroes))
    and
    ChooseHero(GetRandomInt(0, num_heroes))
    ?
    So instead of a random hero… i get… a random hero?!
     
  8. Dirac

    Dirac

    Joined:
    Jun 20, 2011
    Messages:
    249
    Resources:
    3
    JASS:
    3
    Resources:
    3
    I agree with LeP this seems pointless.

    random * random = random
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,283
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Dirac and LeP are right.

    Thing is, the game sets the seed at a random point, and that random point is different each game provided you have "use fixed random seed" disabled.

    Changing the random seed is just changing the position of the randomness but not actually adding any additional randomness.

    GetRandomInt(-(2^31-1), (2^31-1)) would never really need to be called unless it's to break that horrible SetRandomSeed(0) that cinematics do. It's a shame that cinematics try to set the random seed to 0 every time, because you wouldn't think about it unless you had studied Blizzard.j. It used to drive me nuts when I was only working with GUI.
     
  10. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Eh, the point of this is to ensure more unique randomness based on player actions.
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,283
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I think the equation for the randomness is enough unique. Say you have a random seed of x, and x returns for GetRandomInt 124, 234843, 12, 5902, and so on. Then you set the random seed to y, GetRandomInt returns 4543, 91, 4903858, 82383. Both are producing totally random results, and you are not able to guess what the next one would be. Each return of GetRandomInt is unique on its own, and is just as unique as if you were to change the random seed to something else (both are nothing you'd ever expect).
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,283
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I'm scheduling this to be graveyarded.
     
  13. SpiritTauren

    SpiritTauren

    Joined:
    Mar 10, 2009
    Messages:
    200
    Resources:
    2
    Icons:
    1
    Skins:
    1
    Resources:
    2
    Thank you. With the current Reforged fixed seed, you're a lifesaver.