antonylord
New Member
Coding challenge :
Pick a random number between 0-7
Now randomly pick one of the remaining 6 numbers
Now randomly pick one of the remaining 5 numbers
etc.
eg 1,4,6,7,2,0,3,5 (each number is used only once)
Now I remember years ago doing this in C with a linked array and each time you chose a number your shortened the array by changing the pointers. This was elegant as the list from which you could randomly choose the next number only contains the previously unchosen numbers.
How to do this in pbasic?
I can write an awful bt of code using a 1 x 8 array where each time I "use" a number I flag it then keep randomly choosing until I get an unused number but hey - that's not efficient at all.
Anyone shed some light on a smart solution?
Cheers, Antony.
Pick a random number between 0-7
Now randomly pick one of the remaining 6 numbers
Now randomly pick one of the remaining 5 numbers
etc.
eg 1,4,6,7,2,0,3,5 (each number is used only once)
Now I remember years ago doing this in C with a linked array and each time you chose a number your shortened the array by changing the pointers. This was elegant as the list from which you could randomly choose the next number only contains the previously unchosen numbers.
How to do this in pbasic?
I can write an awful bt of code using a 1 x 8 array where each time I "use" a number I flag it then keep randomly choosing until I get an unused number but hey - that's not efficient at all.
Anyone shed some light on a smart solution?
Cheers, Antony.
Last edited: