• 🏆 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!

Random Integer on a Single Player

Status
Not open for further replies.
Hi! I read on this forum that when a single player randoming an integer he will get allways and only the same randomed integer when he is not connected to the internet, as only LAN and INTERNET games are actually using the time of the computer to regenerate a randomed number and on a single player its just a set of prechoosen numbers.
Is there a way to force randomed number on a single player host?
 
how can you tell it didn't help?

I gave each ability on the map a random ability based on randomed integer, if int = 1 give that ability, if int = 2 give the other ability if 3... for 50 abilities, ALT Q (editor test) the map will create all units with set abilities that allways and only have the same ability so that the footman in front will allways have the same ability when the trigger choose ability for it.
Nothing helps - other than delete the units and create new ones which gives them a new order and because of that the abilities will be given in a different order so that the first time 10 units had critical hit and the other time 10 different units will have critical hit, restart the map will not change that fact, there will allways and only be 10 units that have critical hit and those units are allways the same units like in the previews run.

Instead of asking how I can tell it didn't help you should assume I know it because I tested it and it didn't work, can you come up with a different strategy to force the integer to be totaly randomed?
I tried this:
From integer a from 1 to 100
set int = randomed number between 1 and 2

  • For each (Integer A) from 1 to 2, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 2) Equal to 1
        • Then - Actions
          • Set int = (Random integer number between 1 and 2)
        • Else - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • Set int = (Random integer number between 1 and 2)
Conclusion:
The randomed int is different but on the following runs and on the restart, the int will not take place of another integer.
nothing I tried worked.
 
Level 9
Joined
Dec 12, 2007
Messages
489
Instead of asking how I can tell it didn't help you should assume I know it because I tested it and it didn't work, can you come up with a different strategy to force the integer to be totaly randomed?
let me tell you simply, pOke's solution should work in this case, so if that method didn't work, the question lies in the method how you can tell that it didn't work.

your snippet of GUI trigger didn't prove anything and actually bugged since Integer A is used inside the loop itself.

probably there is fault in your trigger, I really suggest you post your map, or if you decide to fix it yourself, try put debug message whenever you roll random number right after you set a random number, see if that number continue to be same or not.

also try test your map by running Warcraft itself, not through Test Map, see if it gives different result.
 
Did you test the map via World Editor ?
Some says the Fixed Random Seed still applies even if you're testing it via World Editor.
How about you test the map via Warcraft III Frozen Throne Custom Game ?

Good idea, I will do as you suggested.
*** attached: the map who refuse to create randomed integer from run to run.
*** if you tested the attched map 2 or 3 times, your enemies will use allways and only the same abilities againts you: the first 2 enemies go frost armor/ polymorth / chain lightning, the 2 units below them go bloodlust / bloodust and the following enemy will go minute missle.
 

Attachments

  • Freedom Force 2 v0.40.w3x
    867.5 KB · Views: 52
Edit: so far no strategy suggested worked, its amazing how 2 people answered and told that this is the one and only way that 100% work and upon testing one can't understand where they got the idea about "this will work" from.
I think that the only way to make it work is to host it on the internet using bnet or on LAN - and about the lan I need to test since I dont want to tell people stuff that are a lie so they go test and find out I lied to them.


Edit #2: I give up, fuck my map and everything it stands for. The map has long loading time, huge days time for creation and what it give back when I need it? same randomed integer over and over, ruins the entire perpus of the map where the player should feel like hes fighting a huge army of unknown magic and spells. So fuck this map and I don't love it anymore, fucking none-randomed without magic fun fucking bitch
 
Level 9
Joined
Dec 12, 2007
Messages
489
interesting thing is, after placing some debug message on the getrandomint function, I did notice the randomed number always the same between game.

so I did a little google on set random seed, and this is what I found.
this post states that using cinematic will set the random seed into 0, thus making GetRandomInt returns same value between each game. I suggest you to avoid using cinematic

or use this to workaround that cinematic bug.
use this custom script before you turn on the cinematic,
set udg_Int = GetRandomInt(0,100000)
then after the cinematic is off, use this custom script:
call SetRandomSeed(udg_Int)
and avoid using random number during the cinematic.

seeing how I found this out in under 1 minute, you really need to learn to use google.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • For each (Integer A) from 1 to 2, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 2) Equal to 1
        • Then - Actions
          • Set int = (Random integer number between 1 and 2)
        • Else - Actions
          • For each (Integer A) from 1 to 2, do (Actions)
            • Loop - Actions
              • Set int = (Random integer number between 1 and 2)

You should use Integer B for one or the other loop.
 
Thanks to all those who answer!
I still don't know the answer but Dark_Axl has brought something really intresting which we all should read: http://www.hiveworkshop.com/forums/graveyard-418/snippet-random-seed-210426/#post2085501
They talk about offline randomness and it seems that one has to create a special trigger to get a random number, its really confusing and its writen in jazz and furtheremore Dark_Axl wrote that it has something to do with cinematic, I'm reading but am still confused.

Edit: I don't understand all those costum jazz commends you mentioned Dark_Axl but since my huge bug was focused on the game initiation trigger, the bug of placing abilities on units is no longer exist since I made the cinematic action to be made after I gave the global units randomed abilities, still, using ability that cause random damage gonna be the same from game to game and I have no idea how to use your jass special commend to prevent it ? (custom script set udg_Int = GetRandomInt(0,100000) show error message) So THANKS A LOT FOR SOLVING A BIG PART OF MY PROBLAM WHICH WAS SEEMS LIKE NOBODY EVEN KNOW IT EXISTED. And can you please bring something that I can use in GUI?
 
Level 9
Joined
Dec 12, 2007
Messages
489
let me use simpler step by step explanation about the link I gave you,

1. Warcraft uses a sets of table filled with random number for random number generation. so its actually not so random after all.

2. whenever the game start, Warcraft automatically rolls a random number as a random seed. this number determine which set of table will be used for random number generation for the whole game. this ensure random number is always different between each game.
imagine this as SetRandomSeed(<insert random number here>)

2. when cinematic is used, it overwrites the random seed the game has specified at start with SetRandomSeed(0). since the random seed is set to 0 after cinematic. any random number generated after that is fixed to the random number table of seed(0).

3. it is not confirmed yet to be related with multiplayer or offline play.

I see that you didn't understand my previous post or the link I gave you,
I suggest you to read again about random seed, that link, and avoid taking early conclusion.
 
let me use simpler step by step explanation about the link I gave you,

1. Warcraft uses a sets of table filled with random number for random number generation. so its actually not so random after all.

2. whenever the game start, Warcraft automatically rolls a random number as a random seed. this number determine which set of table will be used for random number generation for the whole game. this ensure random number is always different between each game.
imagine this as SetRandomSeed(<insert random number here>)

2. when cinematic is used, it overwrites the random seed the game has specified at start with SetRandomSeed(0). since the random seed is set to 0 after cinematic. any random number generated after that is fixed to the random number table of seed(0).

3. it is not confirmed yet to be related with multiplayer or offline play.

I see that you didn't understand my previous post or the link I gave you,
I suggest you to read again about random seed, that link, and avoid taking early conclusion.
Ok. Is there a UGI methode of setting the SetRandomSeed(0) to SetRandomSeed(randomed) to disable cimenatic?
And/Or is there a way to see windows hours and minutes and use it to generate randomed number?
 
Level 9
Joined
Dec 12, 2007
Messages
489
I suggest you to avoid using cinematic or use this to workaround that cinematic bug.

use this custom script before you turn on the cinematic,
set udg_Int = GetRandomInt(0,100000)
then after the cinematic is off, use this custom script:
call SetRandomSeed(udg_Int)
and avoid using random number during the cinematic.

its GUI, not UGI.

create an integer global variable with name Int.
before the cinematic, use GUI custom script and paste set udg_Int = GetRandomInt(0,100000).
after cinematic end, use GUI custom script and paste call SetRandomSeed(udg_Int)
 
It threw no errors for me. Did you do as instructed?

Yes, poke, the thread should be closed since it was reached to conclusion: there is NO WAY to create a random integer once you called the camera of cinematic. There was alot of attempts here that I tried each one of them and there was none who could solve it. The solution was removing cinematic from the map. Good Luck with solving questions that CAN be solved.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
everything about the cinematic mode here what was said is incomplete
Here is full script for cinematics:
JASS:
function CinematicModeExBJ takes boolean cineMode, force forForce, real interfaceFadeTime returns nothing
    // If the game hasn't started yet, perform interface fades immediately
    if (not bj_gameStarted) then
        set interfaceFadeTime = 0
    endif

    if (cineMode) then
        // Save the UI state so that we can restore it later.
        if (not bj_cineModeAlreadyIn) then
            set bj_cineModeAlreadyIn = true
            set bj_cineModePriorSpeed = GetGameSpeed()
            set bj_cineModePriorFogSetting = IsFogEnabled()
            set bj_cineModePriorMaskSetting = IsFogMaskEnabled()
            set bj_cineModePriorDawnDusk = IsDawnDuskEnabled()
            set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)
        endif

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ClearTextMessages()
            call ShowInterface(false, interfaceFadeTime)
            call EnableUserControl(false)
            call EnableOcclusion(false)
            call SetCineModeVolumeGroupsBJ()
        endif

        // Perform global changes
        call SetGameSpeed(bj_CINEMODE_GAMESPEED)
        call SetMapFlag(MAP_LOCK_SPEED, true)
        call FogMaskEnable(false)
        call FogEnable(false)
        call EnableWorldFogBoundary(false)
        call EnableDawnDusk(false)

        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)
    else
        set bj_cineModeAlreadyIn = false

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ShowInterface(true, interfaceFadeTime)
            call EnableUserControl(true)
            call EnableOcclusion(true)
            call VolumeGroupReset()
            call EndThematicMusic()
            call CameraResetSmoothingFactorBJ()
        endif

        // Perform global changes
        call SetMapFlag(MAP_LOCK_SPEED, false)
        call SetGameSpeed(bj_cineModePriorSpeed)
        call FogMaskEnable(bj_cineModePriorMaskSetting)
        call FogEnable(bj_cineModePriorFogSetting)
        call EnableWorldFogBoundary(true)
        call EnableDawnDusk(bj_cineModePriorDawnDusk)
        call SetRandomSeed(bj_cineModeSavedSeed)
    endif
endfunction

As you see, it really calls SetRandomSeed(0), but noone noticed the set bj_cineModeSavedSeed = GetRandomInt(0, 1000000) and SetRandomSeed(bj_cineModeSavedSeed) part somehow

if you want to do something like they said, the script would look like:
  • Example
    • Events
    • Conditions
    • Actions
      • Set Int = (Random integer number between 0 and 10000000)
      • Cinematic - Turn cinematic mode On for (All players)
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call SetRandomSeed(udg_Int)
Int is variable of type Integer
Do this in each trigger where you run cinematics, and when you end cinematics also put the Custom script: call SetRandomSeed(udg_Int)

let me use simpler step by step explanation about the link I gave you,

1. Warcraft uses a sets of table filled with random number for random number generation. so its actually not so random after all.
any proof? this is like claiming warcraft 3 runs internet explorer before it starts and you dont see it.

They could just as much roll number from XOR shift RNG or Mersenne Twister
 
Which is the only time seed is a problem apparently (according to the stuff said in this thread) because multiplayer seeds are random?

Wow that is so smart, you suggested to create hashtable on the game start that would do "Hashtable of integers" and it will create mass mass mass random integer (0-99) and store them so that once I used the cinematic I could simply call the random generator and take hastable integer [x] and do something with it to make it suit the corrent random (0-22 will make some math with 0-99)
and once x reached its limit I will set x=0.
You are truely worthy of your title as forum boss and I think this is the most creative thing I ever heared!.
problams:
1) how to make 0-99 mass integers be 0-22 when I need it? (without ruin the chance of equall to each number?)
2) did I get you right or is there something I am missing that can make it more simple?

the first line should be Custom Script: set udg_Int = GetRandomInteger(0, 1000000)

can you just show how it looks in a trigger?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
you suggested to create hashtable on the game start that would do "Hashtable of integers" and it will create mass mass mass random integer (0-99)
I said use a game cache not a hashtable. Game Caches are persistent storage in single player (which seems to be the only place this is a problem).

1) how to make 0-99 mass integers be 0-22 when I need it? (without ruin the chance of equall to each number?)
2) did I get you right or is there something I am missing that can make it more simple?
Use the normal RNG but if the game is single player you save a random integer in a game cache. Next time the player loads the map you then load this random number from the game cache and use it as a seed to set up the RNG. This would mean the randomness of the next game is based on the actions that occurred in the first (very small chance of predictable results).
 
I said use a game cache not a hashtable. Game Caches are persistent storage in single player (which seems to be the only place this is a problem).


Use the normal RNG but if the game is single player you save a random integer in a game cache. Next time the player loads the map you then load this random number from the game cache and use it as a seed to set up the RNG. This would mean the randomness of the next game is based on the actions that occurred in the first (very small chance of predictable results).

I don't know what game cash is but I do know use hashtables, do you know a math way of moving 0-100 randomed number into 1-24 without ruinning the % of each shot?.
1-24 ~0.04% for each integer to be picked.
0-100 got the randomed X=89, set the integer to maximum of 24 and minimum of 1. X is not set into 24. then 24 has higher chance to be picked than others: the chance is that when 24,25,26....100. is picked then it will be 24.
I see no other way than to make hastable (0-100) and Hashtable2 (1-24) OR AM I WRONG?
Wait, how about:
set Int =0
Run Trigger_1(set randomed X to 1-24)

Trigger_1:
Event--
Conditions--
Actions:
Set Int = Load hashtable Integer(X)
Set X=X+1
If (int less than 4) {
Set Int = 1
Skip remainning actions
}
If (int less than 8){
Set Int = 2
Skip remainning actions
}
// Each integer now has 4% chance, custom made trigger for the range.

Fixed?
 
Last edited:
Sorry for my terrible English, I will try to explain this as best as I can:

What cause this problam:
Trigger action: create cinematic camera = all randomed integers are now the same from run to run.

What people suggested on this site:
Custom script: call SetRandomSeed(udg_Int) = "error message cannot save the map"

What I tried in order to fix without having the error massge:
Before I got into creating cinematic, I create integer[1000] that each contains a random number. set X=0 to have the start of integer[0] with me.
When I need to call on a random number, I call integer[X] and afterwards add X+1.
Result: I was unable to decide the range without hurting the % of each number to hit.

Example:
Call random number between 1 and 10 // each has 10% chance to hit
if I go integer [x] then I would result having 1=1%. 2=1%... 10=remainning chance which is 90%.
Then I created a trigger that fixes that:
random integer 1-9
call integer[x]
if integer[x] was 1-10 set the randomed 1-9 to 1.
if integer[x] was 20-30 set the randomed 1-9 to 2.
Etc.

Now I have 2 more questions:
1) Will it be better to create a unit that has random damage 1-9 and use damage detection on a different dummy unit to do the random culculations, or will it create bigger lag than using integer[1000].
2) What do you think caused the error message to the suggestion that I was given?

I am Sorry that it was hard to read what I tried to explain, I will try to use simpler English now on.
 
Status
Not open for further replies.
Top