Hi,
How does anyone do random numbers with Picaxe chips?
I have this method which seems to work but has anyone got a straight forward way of writing a snippet of program to do this on a Picaxe.
I'm looking for something to seed the random before I use it but not using outside the chip stuff.
Wouldn't it be nice to just have X=RND(6+1)
Here is a way that works but it is still outside the chip for seeding.
For comments.
Kando
How does anyone do random numbers with Picaxe chips?
I have this method which seems to work but has anyone got a straight forward way of writing a snippet of program to do this on a Picaxe.
I'm looking for something to seed the random before I use it but not using outside the chip stuff.
Wouldn't it be nice to just have X=RND(6+1)
Here is a way that works but it is still outside the chip for seeding.
Code:
[color=Green];Random numbers by kando
;Run in the simulator to see it. (Version 6 beta) (neat IR sim handset)
;press a button on the handset to start..[/color]
[color=Blue]settimer [/color][color=Navy]63455[/color][color=Green]; seems to work well with this number!
;i've used irin and a sky remote handset[/color]
[color=Black]main:[/color]
[color=Blue]irin [PLAIN][[/PLAIN][/color][color=Navy]1000[/color][color=Black],main[/color][color=Blue][PLAIN]][/PLAIN][/color][color=Black],[/color][color=Blue]C.3[/color][color=Black],[/color][color=Purple]b0 [/color][color=Green];wait for button press on IR pin use to seed random[/color]
[color=Purple]w12[/color][color=DarkCyan]=[/color][color=Purple]timer[/color][color=Green];collect time when button pressed into w12[/color]
[color=Purple]w0[/color][color=DarkCyan]=[/color][color=Purple]w0[/color][color=DarkCyan]-[/color][color=Purple]w12[/color][color=Green]; (w0 = b0,b1)(w12 = b24 ,b25)[/color]
[color=Blue]for [/color][color=Purple]b5[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]27[/color]
[color=Blue]DO
RANDOM [/color][color=Purple]w0
b2 [/color][color=DarkCyan]= [/color][color=Purple]w0 [/color][color=DarkCyan]/ [/color][color=Navy]199 [/color][color=DarkCyan]// [/color][color=Navy]9 [/color][color=DarkCyan]+ [/color][color=Navy]1[/color][color=Green]; 9 because random x9 change to 6 for dice[/color]
[color=Blue]LOOP UNTIL [/color][color=Purple]b2 [/color][color=DarkCyan]<> [/color][color=Purple]b3
b3 [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]
[color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]b3[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)[/color][color=Green];to see results for testing [/color]
[color=Blue]next [/color][color=Purple]b5[/color]
[color=Blue]end[/color]
Kando