Warcraft III resources & community, 2003–2006 · archived

Random Integer not being random??

9 posts
#1

Random Integer not being random??

OK, so i have a powerup buff like in dota, a rune that gives u an ability. The type of rune is meant to spawn randomly.
My trigger is:
Rune 1 Respawn
Events
Time - T_Rune1_Respawn expires
Conditions
Actions
Set I_RandRune = (Random integer number between 1 and 6)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
I_RandRune Equal to 1
Then - Actions
Item - Create Rune - Attack at (Center of Rune Spawn 1 <gen>)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
I_RandRune Equal to 2
Then - Actions
Item - Create Rune - Defence at (Center of Rune Spawn 1 <gen>)
Else - Actions

The problem is that every time it ALWAYS spawns the 5th rune, then the 4th rune twice, then the 1st rune, every game!

i added a second randomisation after the first to see what would happen and all that happens is the sequence is changed in which they spawn but it is always the same EVERY game!!! :( plz help, i hope its just code error i've made!
#2
dont use the variable, use the integer comparison (math random number)
#3
I_RandRune Equal to 1

That is an integer comparison, i don't know what you mean, don't use variable.
#4
i think you have to change something in the WE's preferences. there is sthg with random integers. there is what you need... i hope
#5
You may have setup the trigger improperly, I'm not sure exactly without seeing it but I guess you use the if then else statement repeating the if then through the else. Ill have something for you in a bit
#6
Use this:
function Trig_Rune_1_Respawn_Actions takes nothing returns nothing
local integer i=GetRandomInt(1, 6)
if i==1 then
 call CreateItemLoc( 'rde1', GetRectCenter(gg_rct_RectName) )
elseif i==2 then
 call CreateItemLoc( 'rwiz', GetRectCenter(gg_rct_RectName) )
elseif i==3 then
 call CreateItemLoc( 'rag1', GetRectCenter(gg_rct_RectName) )
elseif i==4 then
 call CreateItemLoc( 'hcun', GetRectCenter(gg_rct_RectName) )
elseif i==5 then
 call CreateItemLoc( 'mcou', GetRectCenter(gg_rct_RectName) )
else
call CreateItemLoc( 'befv', GetRectCenter(gg_rct_RectName) )
 endif 
endfunction

//===========================================================================
function InitTrig_Rune_1_Respawn takes nothing returns nothing
    set gg_trg_Rune_1_Respawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Rune_1_Respawn, udg_T_Rune1_Respawn )
    call TriggerAddAction( gg_trg_Rune_1_Respawn, function Trig_Rune_1_Respawn_Actions )
endfunction



Change the raw values to the values of the runes you wish to use, change the location of the rect you wish to use by renaming "RectName" to your rect, it must retain the "gg_rct_" and if you use a space replace it with an underscore (_).

And go to File > Preferences > Test Map. Make sure that box is NOT CHECKED[/jass]
#7
no u rly wont need jass. i said u should use math random number in my last post

if: math random number => random number between 1 and 6 is equal to 6
then: .........
else: if: math random number ......... to 2
then: ........
else...... if: ........... etc etc
#8
And go to File > Preferences > Test Map. Make sure that box is NOT CHECKED

Haha! Thank You! That's all i apparantly needed, to untick the "use fixed random seed" button. Not really sure what it does but by unticking it made it random.

Ramza i tested your solution first and it worked as i expected, at least if i did it the way you meant. What it did was run a random number 6 times, once each time for each of the 6 possible runes in the if/then/else statements.

The problem is that each random number generated for each if/then/else statement is localised to that if/then/else. This means that if the 1st if/then/else which is checking for 1, comes up with a random number = 6, and the 2nd if/then/else which is checking for 2, comes up with 1, etc. etc. Then you will have the rune sometimes never spawn unless you put the whole thing in a loop.
#9
ohye i kknow what u mean, u can solve that by, changing the last if,then, else's 'else' from a 'DoNothing' to an itemdrop