[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