Random Array from anything?

Sartan

New Member
Reaction score
23
lets say i have... a integer with 7 arrays called:
int[0, int[1]...int[6]
how do i "pick" a random int[x] of these, without being able to pick the same int twice?
 

Trollvottel

never aging title
Reaction score
262
first fill the fields:

var[1] = X
var[2] = X
var[3] = X
var[4] = X
var[5] = X
var[6] = X

get a new variable called i, its an integer and has the value 6

loop
now get a random int between 1 and i and call it r.

save the value of var[r] in tempvar
now just set var[r] to var
reduce i by 1.
endloop
 

Failenx

TH.net Regular
Reaction score
7
tempBoolean is type "Boolean" with initial value of False
tempBoolean2 is an Array with a size of 7 and of type "Boolean" with initial value of False.
RandomInt is type "Integer" with initial value of 0
Trigger:
  • Custom script: loop
    • Custom script: exitwhen (udg_tempBoolean == true)
    • Set RandomInt = (Random integer number between 0 and 6)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • tempBoolean2[RandomInt] Equal to False
    • Then - Actions
    • Custom script: set udg_tempBoolean = true
    • Set tempBoolean2[RandomInt] = True
    • Else - Actions
    • Custom script: endloop


This was done free hand, if you'd like to know where to put your actions at to make this work for your game, feel free to PM me. And I'll make it look neater. (I'll make it JASS too.)
 

Sartan

New Member
Reaction score
23
plz make a more JASS loking example :)
and trollvotel, how is your trigger working? is it removing the int that is picked or?
 

Trollvottel

never aging title
Reaction score
262
yes thats right, its just picking one and setting the last int in this list to this position. kind of permutation i think.
the example by failenx just picks a random slot until it hits a free slot. that can work, but it could also go horribly wrong, remember the random numbers in warcraft III are not really random...
well i dont think i have to make a jass example, the code is not too complicated and you can learn by doing ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top