Hi all,
I wanted to make some code to generate a list of 30 random numbers between 1 and 30 with no repeats (just using PE as a helpful tool to do this). I couldn't work out how to do it without using 30 variables to store each number in so that I could check if a number had already been used. That seemed to require writing the whole thing out 30 times and changing the variable name that it was stored in each time. So, I had an idea. I wrote some other code to write this code
I then sat back and let that run for a few minutes while it wrote my code for me. When it was finished, I simply copied the code from the sertxd box into PE and ran that. And out came a list of 30 numbers, between 1 and 30, in a random order, with no repeats! What fun! (well 31 if you count the "0" )
Anyway, for future reference, I'd really appreciate it if someone could tell me the normal way to generate a list of 30 numbers from 1-30 in a random order.
Thanks,
David.
I wanted to make some code to generate a list of 30 random numbers between 1 and 30 with no repeats (just using PE as a helpful tool to do this). I couldn't work out how to do it without using 30 variables to store each number in so that I could check if a number had already been used. That seemed to require writing the whole thing out 30 times and changing the variable name that it was stored in each time. So, I had an idea. I wrote some other code to write this code
Code:
let w2 = 65535 / 31
main: do
sertxd ("lable",#b0,": random w27",CR)
sertxd (" let w27 = w27 / ",#w2,CR)
sertxd (" let b",#b0," = b54",CR)
if b0 > 0 then
let b1 = b0
do
let b1 = b1 - 1
sertxd (" if b",#b0," = b",#b1," then lable",#b0,CR)
loop until b1 = 0
endif
sertxd (" sertxd (#b",#b0,",CR)",CR)
inc b0
loop while b0 < 31
end
Anyway, for future reference, I'd really appreciate it if someone could tell me the normal way to generate a list of 30 numbers from 1-30 in a random order.
Thanks,
David.