(12C) Random Number (No Seed Needed)
12-31-2017, 08:13 AM (This post was last modified: 01-05-2018 03:45 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 496 Joined: Dec 2016
(12C) Random Number (No Seed Needed)
This Random Number Generator program used Pi and e^x to generate number between zero and one that no starting seed is necessary.
This sample Random Generator program generate 6 digits integers.

Code:
 RCL 0 355 ENTER 113 / + e^x FRAC STO 0 EEX 6 x INTG

Example: R/S --> 676,246 R/S --> 505,826 R/S --> 375,537

Above result will be difference than this example.

Here is the Random Generator portion between 0 to 1 with automatic random generator loop.

Code:
 RCL 0 355 ENTER 113 / + e^x FRAC STO 0 PSE GTO 01

Randomness loop result.

Gamo

Gamo
12-31-2017, 08:34 AM
Post: #2
 grsbanks Senior Member Posts: 833 Joined: Jan 2017
RE: (12C) Random Number (No Seed Needed)
You can save a few bytes of code and generate numbers from 1 to 999999 (instead of 999998).

The result of FRAC is necessarily going to be less than one, so multiply it by "1E6" instead of 999999 before taking the integer part.

Either that or do what most PRNGs do on calculators and just return the fractional part.
12-31-2017, 09:07 AM (This post was last modified: 12-31-2017 09:08 AM by Gamo.)
Post: #3
 Gamo Senior Member Posts: 496 Joined: Dec 2016
RE: (12C) Random Number (No Seed Needed)
Thank You grsbanks

Very good idea by using the EEX
Would like to get the range between
100,000 to 999,999

Gamo
12-31-2017, 10:10 AM
Post: #4
 grsbanks Senior Member Posts: 833 Joined: Jan 2017
RE: (12C) Random Number (No Seed Needed)
Instead of "1 EEX 6 x", use "9 EEX 5 x EEX 5 +"
12-31-2017, 09:11 PM (This post was last modified: 12-31-2017 09:12 PM by Dieter.)
Post: #5
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: (12C) Random Number (No Seed Needed)
(12-31-2017 08:13 AM)Gamo Wrote:  This Random Number Generator program used Pi and e^x to generate number between zero and one that no starting seed is necessary.

I assume you want to say that it also works for seeds ≤ 0.
Replace ex with x² and you got one of the classic PRNGs for programmable calculators.

(12-31-2017 08:13 AM)Gamo Wrote:  This sample Random Generator program generate 6 digits integers.

It generates integers between 0 and 999998.

(12-31-2017 08:13 AM)Gamo Wrote:  Here is the Random Generator portion between 0 to 1 with automatic random generator loop.
...
This can test to see the Randomness result.

?!? – how do you test the statistical properties this way?

(12-31-2017 09:07 AM)Gamo Wrote:  Very good idea by using the EEX
Would like to get the range between
100,000 to 999,999

If you got a random number r between 0 and 0,9999... you can easily transform it into a random integer between a and b (inclusive) by calculating int((b–a+1)*r) + a. So if you want an interval from 100000 to 999999 the transformation is int(900000*r)+100000, as grsbanks already noted.

Dieter
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)