Random numbers and the Propeller
Wolfbrother
Posts: 129
Hi all.
I am trying to look at generating a random number to determine how many times this device I am making should spin around it's axis.· So I edited most of the motor stuff out of my code so I could post it here. What I don't get is that this thing is pretty consistent at the numbers it outputs. It starts with 5, 8, 16, 18, 6, 2, 13, 8... and then eventually settles into a pattern of 2,13 and 6. Does anyone have a clever way I can generate truly random numbers from 1 to 24 or can point the error of my ways here? What I found searching the forum was all in PASM and that's just something I don't get at all. I'm struggling with Spin.
Thanks.
Dave
I am trying to look at generating a random number to determine how many times this device I am making should spin around it's axis.· So I edited most of the motor stuff out of my code so I could post it here. What I don't get is that this thing is pretty consistent at the numbers it outputs. It starts with 5, 8, 16, 18, 6, 2, 13, 8... and then eventually settles into a pattern of 2,13 and 6. Does anyone have a clever way I can generate truly random numbers from 1 to 24 or can point the error of my ways here? What I found searching the forum was all in PASM and that's just something I don't get at all. I'm struggling with Spin.
Thanks.
Dave
Comments
var long ran
.....
ran := cnt ' initialize ran from the clock
x := ran? ' get the first random number
y := ran? ' get a second random number
' now do whatever you want with x and y, but leave ran unchanged until the next time you need a random value.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $24.99 has backlight driver and touch sensitive decoder.
If you have not already. Add yourself to the prophead map
I really got kind of overwhelmed reading the object on the OBEX, because it talked about never getting really random numbers unless you used some other input. I tried to paste that code into my program, but I'm doing something wrong there too. I'm basically trying to figure this·out on the fly and really some of it isn't very intuitive to me yet. That's the file called Testing clock call for CoC 2.1, maybe I did something obvious there?
Thanks.
Post Edited (Wolfbrother) : 1/19/2010 3:42:29 AM GMT
OBJ
rr : "RealRandom"
at the begining of your first function run
rr.start
then just substitute ran? with
rr.random
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board now in. $24.99 has backlight driver and touch sensitive decoder.
If you have not already. Add yourself to the prophead map