• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] How to create random pick system? Details inside.

Status
Not open for further replies.
Level 18
Joined
Jun 2, 2009
Messages
1,276
Hello. I am going to ask for whole system this time. Here is the example.

You have 5 integers.
Game selects randomly 3 of the integers and sorts.
Same integer cannot be selected more than once.

Example

Game picked numbers 1, 3 and 4.
The trigger with number 1 runs, then runs 3 and runs 4.
 
The basic idea is to create a set of numbers, such as an array set. Then pick a random element from that set, removing it in the process. These picked elements then are stored in a list, such as an array list. Repeat until you picked the number of elements desired. Then you can sort the list using any sorting algorithm, such as linear sort.

The use of a set to store the numbers to pick from allows an optimisation for removal if implemented using an array. The removed element can be replaced with the last element. If an array list was used then all subsequent elements have to be moved down 1 place.
 
Status
Not open for further replies.
Back
Top