Discussion:
Rolling Dice
Jim Wagner
2016-09-18 21:29:27 UTC
Permalink
Greetings NUG -

I want to create a small program for a friend. Said program is to demonstrate the statistics of dice rolling. I’ve never dealt with Xojo’s random number generation. So, I am looking for a way to generate quasi-random selections from the set {1, … ,6} while maintaining the equal odds for any number in that set. Suggestions are, therefore, solicited.

I can deal with multiple dice, certain defects, data presentation, and such. Its that initial random number generation that has me a bit buzzed.

Many thanks
Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home



_______________________________________________
Unsubscribe by sending a message to:
<nug-leave@
Thomas Moore
2016-09-18 21:39:46 UTC
Permalink
Dear Jim,

I think that it can be as simple as

n = Floor(Rnd*6) + 1

The Rnd function generates a pseudorandom number between 0 and 0.999999... Multiplying by 6 yields a random number between 0 and 5.99999.... Rounding down to the next lowest integer generates an integer with equal probability between 0 and 5, and adding one yields a number between 1 and 6.

Xojo has a more complicated Random class which can also deliver the functionality you need (look at the LR).

Best wishes, Tom
Post by Jim Wagner
Greetings NUG -
I want to create a small program for a friend. Said program is to demonstrate the statistics of dice rolling. I’ve never dealt with Xojo’s random number generation. So, I am looking for a way to generate quasi-random selections from the set {1, … ,6} while maintaining the equal odds for any number in that set. Suggestions are, therefore, solicited.
I can deal with multiple dice, certain defects, data presentation, and such. Its that initial random number generation that has me a bit buzzed.
Many thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.c
Markus Winter
2016-09-18 21:39:05 UTC
Permalink
What's wrong with using the build in random class?

http://docs.xojo.com/index.php/Random

Use TotalSeconds as seed. Should be random enough.

Markus

Sent from my iPad
Post by Jim Wagner
Greetings NUG -
I want to create a small program for a friend. Said program is to demonstrate the statistics of dice rolling. I’ve never dealt with Xojo’s random number generation. So, I am looking for a way to generate quasi-random selections from the set {1, … ,6} while maintaining the equal odds for any number in that set. Suggestions are, therefore, solicited.
I can deal with multiple dice, certain defects, data presentation, and such. Its that initial random number generation that has me a bit buzzed.
Many thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <
Jim Wagner
2016-09-18 22:11:13 UTC
Permalink
Thanks,

That is simple enough. I was worried about converting real numbers to integers and what that would do to the distribution.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Markus Winter
What's wrong with using the build in random class?
http://docs.xojo.com/index.php/Random
Use TotalSeconds as seed. Should be random enough.
Markus
Sent from my iPad
Post by Jim Wagner
Greetings NUG -
I want to create a small program for a friend. Said program is to demonstrate the statistics of dice rolling. I’ve never dealt with Xojo’s random number generation. So, I am looking for a way to generate quasi-random selections from the set {1, … ,6} while maintaining the equal odds for any number in that set. Suggestions are, therefore, solicited.
I can deal with multiple dice, certain defects, data presentation, and such. Its that initial random number generation that has me a bit buzzed.
Many thanks
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com

Continue reading on narkive:
Loading...