Randomize number order

bugbear

New Member
Reaction score
3
I want to make an integer array of 20 in size, and i want each part of the array to have a number between 1 and 20, but none can have the same number. Does anyone have an idea of how to make a trigger that can randomize the variables in this fashion?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
You could do it the other way around, and take one out at random as needed:

Setup:
Set Count = 20
For each Integer A from 1 to Count
- Set Array[Integer A] = Integer A

Get a number:
Set TempInteger = Random integer between 1 and Count
do something with Array[TempInteger]
Set Array[TempInteger] = Array[Count]
Set Count = Count - 1



Alternatively, randomize the order inside the array:

For each Integer A from 1 to Count
- Set Integer1 = Random integer between 1 and Count
- Set Integer2 = Random integer between 1 and Count
- Set TempInteger = Array[Integer1]
- Set Array[Integer1] = Array[Integer2]
- Set Array[Integer2] = TempInteger
 

bugbear

New Member
Reaction score
3
Can you convert that pseudo-code into WE format so I can visualize it better? Also, is there code in JASS that can make a loop repeat until a condition is met? If so that could be an easy way to do it by causing the loop to repeat until the other integers in the array no longer matches any of the other numbers.

The purpose is that I am making a map with 20 minigames, like Skibi's, and I want to randomize the minigames, but I don't want any minigame to be replayed until all have been played.
 
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