• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Random number with condition

Status
Not open for further replies.
Set it normally the first time. Then, to get the second number, increment the first by another random int with a one-smaller range and take the result modulo the expected output range. (If you need a lower bound other than 0, it's a simple arithmetic operation to shift the results.)

Example:
  • Set SomeVar = (Random integer number between 0 and 10)
  • Set SomeVar = ((SomeVar + (Random integer number between 1 and 10)) mod 11)
(I assume you want to do something between the two operations. Otherwise, you'll of course want to assign to a different variable the second time.)
 
After a few tests I found out, that this is not I am looking for. Is there a way to use random number from some set of numbers (the same way as random unit from N unit group or random player from N player group, etc.)? Then I will easily remove this number from the set, so it would only have the numbers, which have not been use yet.
 
That would be really hard to implement, because I need 10 numbers, which as they are randomed, they cannot be randomed again. I just asked if there is an easy way like with unit groups, that it will number group and I will just take random number from this group and then remove it, so it cannot be randomed again.

I need this to work for the numbers the same way:
  • Set unit_group = (Random 1 units from (Units in (Playable map area)))
 
If I understand correctly, you want to pick a random item from a set (regardless of type), right?

All you have to do is pick a random integer N between 0 and the number of items in your set.
Then, your random item will be the one at index N.

  • Set N = (Random integer number between 1 and ItemsInSet)
  • Set PickedItem = Set[N]
You can then remove the item from the set if you dont want it to be used again.
 
How can I set random number variable two times, but for the second set I need to set it without the number, which was set in the first set of the variable?
For small number ranges make a set (using an array) of the numbers, select a random element and then remove that element from the set, repeat as required.

For a large number range you track which numbers have been rolled, and then keep retrying a random number until you get one not in that set. To prevent potential infinite loops you might want a safety clause that after 10 or so attempts you default to a value, possibly generated by the rolled number list.
 
Status
Not open for further replies.
Back
Top