• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Random int, but not an int that's been used yet.

Status
Not open for further replies.
Level 6
Joined
Jan 8, 2009
Messages
140
How do I go about doing random between 1 and MyVar except it doesn't pick say 1 2 4 2 1 2 3 2 4 2, it would only be numbers that haven't been picked yet, then repeating again once all are picked.
 
Level 6
Joined
Jan 8, 2009
Messages
140
Are you asking how to pick random random numbers, but once a random number is picked, that picked number cannot be picked again? Like taking cards out of a deck?

yes exactly, and when the 'deck' is empty it starts again with a new 'deck'.
 
Level 10
Joined
Apr 4, 2010
Messages
509
I'm not good with numbers, but I made exactly that using a Unit Variable, an Integer Variable, and a Unit Group. EDIT: Added test map.
  • Deck
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Labling the Cards --------
      • -------- There are Ten in this case --------
      • Set Loop_Amount = 0
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set Loop_Amount = (Loop_Amount + 1)
          • Unit - Create 1 Footman for Neutral Passive at (Center of (Playable map area)) facing Default building facing degrees
          • Unit - Set the custom value of (Last created unit) to Loop_Amount
          • Unit Group - Add (Last created unit) to Temp_Group
      • -------- Calling out the name of the card and removing it from the deck. --------
      • For each (Integer A) from 1 to (Number of units in Temp_Group), do (Actions)
        • Loop - Actions
          • Set Temp_Unit = (Random unit from Temp_Group)
          • Game - Display to (All players) for 30.00 seconds the text: (String((Custom value of Temp_Unit)))
          • Unit - Remove Temp_Unit from the game
          • Unit Group - Remove Temp_Unit from Temp_Group
 

Attachments

  • Deck Randomiser.w3x
    16.5 KB · Views: 35
Use a static array and a dynamic array. That's what I do in iPool. Or you can just use iPool and remove the value once the value is randomly picked. IPool you can find in my vJass resources in my signature.

To make what you want in GUI, you would start with this template:

  • Init Array
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Set ArrayValue[0] = 1
      • Set ArrayValue[1] = 7
      • Set ArrayMax = 1 //the last index in the array
      • Trigger - Run Fill Stack from Array (ignoring conditions)
  • Fill Stack from Array
    • Events
    • Conditions
    • Actions
      • For each Integer A from 0 to ArrayMax, do
        • Loop - Actions
          • Set StackValue[StackCount] = ArrayValue[(Integer A)]
          • Set StackCount = (StackCount + 1)
  • Pop from Stack
    • Events
    • Conditions
    • Actions
      • Set StackCount = (StackCount - 1)
      • Set IntegerIndex = (Random integer number between 0 and StackCount)
      • Set IntegerValue = StackValue[IntegerIndex]
      • If - Multiple
        • If - Conditions
          • StackCount is Equal to 0
        • Then - Actions
          • Trigger - Run Fill Stack from Array (ignoring conditions)
        • Else - Actions
          • Set StackValue[IntegerIndex] = StackValue[StackCount]
 
Status
Not open for further replies.
Top