• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] Random Seed

Level 31
Joined
Jul 10, 2007
Messages
6,306
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.

JASS:
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.
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
537
Are you aware of File -> Preferences -> Test Map -> Checkbox "Use Fixed Random Seed"?
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
537
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.

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?!
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
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.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
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).
 
Top