• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Unsorted Unique Integer Set Generator v1.0.0.0

  • Like
Reactions: gusanomental
Well this is a simple but asked for little template.

It is a random integer generator that is very easy to use. You call the function and give it a minimum and maximum integer value.
Then you call the other function to return the randomized integers to do whatever you want with.
I know this is easy to do however i believe it is useful as a template.

This can be used for a ton of things the list is just about endless.
This can be used as a random non repeating hint generator. You set your hints in an array then set the random integers to it. ( example below)
It can be used as a random hero pick with non repeating heroes being picked for the players.
It has plenty of good uses.
Anything that needs a random non repeating integer set this will do it.

Thanks for the name magtheridon96

  • UnsortedUniqueIntCode
    • Events
    • Conditions
    • Actions
      • -------- --------
      • -------- This function generates a set of random integers from 1 to the maxValue you give it. --------
      • -------- This is just the generator. --------
      • -------- --------
      • For each (Integer randomInt1) from randomIntMinValue to randomIntMaxValue, do (Actions)
        • Loop - Actions
          • -------- This sets the integer array to values so we can then randomize them. --------
          • Set randomIntGeneratorArray[randomInt1] = randomInt1
      • Custom script: endfunction
      • -------- --------
      • -------- This function returns randomized integers that won't repeat. --------
      • -------- Make sure you don't use the tempIntArray variable between calling the generator and returning the integer values. --------
      • -------- Here I de-index and reduce the maxValue so that the integers stay random. --------
      • -------- --------
      • Custom script: function GenerateUniqueRandomInteger takes nothing returns integer
      • -------- --------
      • -------- this gets a random index which retrieves the random integer. --------
      • Set randomInt1 = (Random integer number between randomIntMinValue and randomIntMaxValue)
      • -------- --------
      • -------- This is the random integer that gets returned --------
      • Set randomInt2 = randomIntGeneratorArray[randomInt1]
      • -------- --------
      • -------- Now i de-index the random integer so it doesn't repeat. --------
      • Set randomIntGeneratorArray[randomInt1] = randomIntGeneratorArray[randomIntMaxValue]
      • -------- --------
      • Set randomIntMaxValue = (randomIntMaxValue - 1)
      • Custom script: return udg_randomInt2
  • testing
    • Events
      • Player - Player 1 (Red) types a chat message containing <Empty String> as A substring
    • Conditions
    • Actions
      • Set tempInt1 = (Integer((Entered chat string)))
      • -------- Here is how you register the random integer. Enter an integer and it will use that as a max value. Then it will show you all the integers in a randomized pattern. --------
      • Set randomIntMinValue = 1
      • Set randomIntMaxValue = tempInt1
      • Trigger - Run RandomIntGeneratorCode <gen> (ignoring conditions)
      • For each (Integer tempInt) from 1 to tempInt1, do (Actions)
        • Loop - Actions
          • Custom script: set udg_tempInt2 = GenerateUniqueRandomInteger()
          • Game - Display to (All players) the text: (String(tempInt2))
  • Hint init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer tempInt) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set hintStrings[tempInt] = (This is hint message number + (String(tempInt)))
      • -------- Now i register unique integers --------
      • Set randomIntMinValue = 1
      • Set randomIntMaxValue = 10
      • Trigger - Run UnsortedUniqueIntCode <gen> (ignoring conditions)
      • For each (Integer tempInt) from 1 to 10, do (Actions)
        • Loop - Actions
          • Custom script: set udg_tempInt2 = GenerateUniqueRandomInteger()
          • -------- I set the arrayed variables to hold the unique integer to be used when showing the hints. --------
          • Set hintIntegerArray[tempInt] = tempInt2
  • Show hints
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set hintMaxInteger = (hintMaxInteger + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • hintMaxInteger Greater than 10
        • Then - Actions
          • Trigger - Run Hint init <gen> (ignoring conditions)
          • Set hintMaxInteger = 0
          • Game - Display to (All players) the text: Next set of random ...
        • Else - Actions
          • Game - Display to (All players) the text: hintStrings[hintIntegerArray[hintMaxInteger]]
Keywords:
random, random integer, random integer generator, template, random int, dimf, deathismyfriend
Contents

Template Map (Map)

Reviews
17:47, 25th Sep 2013 PurgeandFire: Good stuff. Useful. The variable names are a bit awkward, usually GUI variables are Start Case e.g. RandomIntegerVariable, rather than camelCase. It is okay though. Prefixes would also be nice. :D But it is...

Moderator

M

Moderator

17:47, 25th Sep 2013
PurgeandFire: Good stuff. Useful.

The variable names are a bit awkward, usually GUI variables are Start Case e.g. RandomIntegerVariable, rather than camelCase. It is okay though. Prefixes would also be nice. :D But it is really up to you.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
it provides a random integer set. basically you give a minimum and maximum values and it returns those integers in a random order.

Take random hints for example. Say you have 10 hints that you want displayed. The hints are in an array indexed from 1 to 10. ( lets call it hintArray[]) You don't want them to repeat. Well you use this system by giving a minimum and maximum value.
So we give a 1 and 10.
Then you use the loop that returns it and set an integer array that you don't overwrite. ( lets call it hintArrayRandom[])
You run the trigger to generate. Then you put this in the loop. integerLoop is the looping integer.
  • Custom script: set udg_hintArrayRandom[ udg_integerLoop] = GenerateRandomIntegersReturn()
Now you use an integer to count when a hint is given. ( lets call it hintCounter)
So we do this.
  • Game message - Display text hintArray[hintArrayRandom[hintCounter]]
  • Set hintCounter = hintCounter + 1
now your hints will be in a random order and won't repeat.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
what you mean by won't repeat is..
when my hint is randomed, you can't get that hint again?

as in if you have 10 hints then it will run through those 10 hints b4 it repeats.

The set of numbers you give it will never repeat. Try the test map just type in a number no dash it will then display them with a game message in a random order that won't repeat.

Example: the pic has 20 numbers being displayed at the moment
 
Top