Shop
OBEX
P1 Docs
P2 Docs
Learn
Events
random number — Parallax Forums
toggle menu
Categories
Discussions
Sign In
·
Register
Sign In
·
Register
Categories
Discussions
Sign In
·
Register
×
Home
›
Propeller 1
random number
Jonathan Holle
Posts:
48
2010-08-22 01:06
edited 2010-08-22 08:33
in
Propeller 1
Hi all,
Do you know how I could generate a random number from 1 to 6 as a dice ?
Comments
Phil Pilgrim (PhiPi)
Posts:
23,514
2010-08-22 01:30
edited 2010-08-22 01:30
dice_roll := ||(? seed) // 6 + 1
where
seed
is a
long
. If that doesn't make sense, look up the
?
operator in the Spin manual.
-Phil
Jonathan Holle
Posts:
48
2010-08-22 02:48
edited 2010-08-22 02:48
Thanks for your answer. This don't works correctly for my application. Because it need a reset in order to get a new result, I would like to get a new random number everytime the function is called ... :-/
PJAllen
Banned
Posts:
5,065
2010-08-22 06:48
edited 2010-08-22 06:48
You need a re-seeding source (a photocell or...) or the die will, naturally, turn up the same result every time.
Phil Pilgrim (PhiPi)
Posts:
23,514
2010-08-22 08:33
edited 2010-08-22 08:33
If you need a different result after every reset, you could also try Chip's Real Random object in the OBEX:
http://obex.parallax.com/objects/62/
-Phil
Sign In
or
Register
to comment.
Comments
where seed is a long. If that doesn't make sense, look up the ? operator in the Spin manual.
-Phil
http://obex.parallax.com/objects/62/
-Phil