George Krietsepis Posts: 272
- I need to randomly select 10 numbers from 1-100 and store them in an array. Random_number(101) selects a number in range 0 <= number < 101 but zero must be excluded.
I could make some piece of code to check if the selected number is zero:
for (iNumber= 1 ; iNumber <=10 ; iNumber ++)
iNumberArray[iNumber] = random_number(101);
while ( iNumberArray[iNumber] == 0 ) iNumberArray[iNumber] = random_number(101); }
I need then to check these 10 numbers to be different for each other. If there are equal numbers, it should re select different ones
Finally I need to short them from the lower to the higher number
Basically, I’d like to ask some help for 2 and 3.
You could do something like this. I have checked this quickly and it works as expected, but depending on how 'paranoid' you are, it could be worth checking this more thorough.
1 - generate the array
You can check the array with debug. You can change some array members to be duplicates of others there also, to check the next function.
2 - check for duplicates
3 - Sort the array
This is a 'standard' insertion sort routine. If you want to know how it works, just Google. Lots of examples.
I tested these functions with simple triggers from pulsing channels on a virtual device with 'control a device' and checking the results in 'debug' but there are may ways of doing this.