Uniform Random Number Algorithm

01192017, 06:09 PM
Post: #1




Uniform Random Number Algorithm
I don't know if this has been discussed before, but my new prime and old HP71B use the same algorithm for generating random numbers. If you set the seed to 1 (RANDOMIZE(1) for the 71B) you get the following series:
.73136... .77202... .989727... .248998... and so on. 

01192017, 08:46 PM
Post: #2




RE: Uniform Random Number Algorithm
Yup. The math library was reimplemented in portable C code from the older Saturn assembly/sysrpl back for the 20/30b calculators and has been used moving forward.
TW Although I work for the HP calculator group, the views and opinions I post here are my own. 

01192017, 10:06 PM
Post: #3




RE: Uniform Random Number Algorithm
Thanks.
I am busy programming my goto first program on all my new languages. It uses random numbers to calculate pi. I first used it on an IBM 360 in the 70's. (Sorry, no speed bench mark for that one.) 

01222017, 02:33 AM
Post: #4




RE: Uniform Random Number Algorithm
Would be great if HP Prime adopted a better RNG, like Mersenne Twister. Machine is so modern and capable, but not for real simulations.


01222017, 06:12 PM
Post: #5




RE: Uniform Random Number Algorithm
(01222017 02:33 AM)mark4flies Wrote: Would be great if HP Prime adopted a better RNG, like Mersenne Twister. Machine is so modern and capable, but not for real simulations. The CAS does use better generators... TW Although I work for the HP calculator group, the views and opinions I post here are my own. 

01232017, 04:24 PM
Post: #6




RE: Uniform Random Number Algorithm
So what CAS command would get me a uniform random number from 0 to 1? I can find random polynomials and random vectors and even random numbers from various distributions, but no random numbers.


01232017, 05:21 PM
Post: #7




RE: Uniform Random Number Algorithm
rand()  lowercase
TW Although I work for the HP calculator group, the views and opinions I post here are my own. 

01232017, 05:24 PM
(This post was last modified: 01232017 05:48 PM by KeithB.)
Post: #8




RE: Uniform Random Number Algorithm
Maybe that should be in the manual. 8^)
ETA: It does not show up in the oncalculator help, either. 

01232017, 06:02 PM
Post: #9




RE: Uniform Random Number Algorithm
For more info you can check the (prime related) giac/xcas help system.


01232017, 06:33 PM
Post: #10




RE: Uniform Random Number Algorithm
It is specifically NOT in the manual by design to keep things simple. Same reason why it doesn't appear in the catalog  only power users highly interested in such things will ever have a need for anything other then a "more then good enough" random generator.
Having multiple functions that do (to the normal, nonpower user) identical things is not really a good idea in general. We'd then have to explain why all the random number generation seed value setting is different for different functions, why one is slower then the other, why different generators are used, etc. This prevents people who might get confused from stumbling across it, not matching results that others are getting, and so on  while allowing users like yourself to access it. The alternative would be just to remove it completely. TW Although I work for the HP calculator group, the views and opinions I post here are my own. 

01232017, 06:56 PM
Post: #11




RE: Uniform Random Number Algorithm
Actually the Prime CAS does not use the Mersenne Twister, while giac/xcas does, more precisely tinymt32.c which has the following copyright header
Code: /** Code: r = unsigned ((1664525*ulonglong(r)+1013904223)%(ulonglong(1)<<31)); 

01232017, 07:25 PM
Post: #12




RE: Uniform Random Number Algorithm
Regarding the "secret" rand function, I think it's the only builtin random function that can be used to generate a list of random integers without repetition. This is also referred to as "selection without replacement".
Example: rand(10,0,9) > all ten singledigit integers, without any repeats, randomly shuffled. RANDINT doesn't do this; it allows repeats. N.B. If you want to use rand(a,b,c) in Home, then the "Change apparent integers into exact integers" setting (CAS Settings, page 1, 3rd line, right end) must be checked. <0ΙΈ0> Joe 

01252017, 10:04 AM
Post: #13




RE: Uniform Random Number Algorithm
Looks like "rand" is wrongly named  It should be "randperm".


01252017, 03:41 PM
Post: #14




RE: Uniform Random Number Algorithm
Except if you call it with no arguments you just get a single random number between 0 and 1 with a uniform distribution.


01252017, 06:19 PM
Post: #15




RE: Uniform Random Number Algorithm
(01232017 06:33 PM)Tim Wessman Wrote: It is specifically NOT in the manual by design to keep things simple. Same reason why it doesn't appear in the catalog  only power users highly interested in such things will ever have a need for anything other then a "more then good enough" random generator. How about an Advanced Users Guide for power users that includes more information than the standard manual does? The argument that hiding information will make something simpler to use seems specious to me. Tom L Tom L Cui bono? 

01262017, 01:26 AM
Post: #16




RE: Uniform Random Number Algorithm
(01232017 06:56 PM)parisse Wrote: Actually the Prime CAS does not use the Mersenne Twister, while giac/xcas does, more precisely tinymt32.c which has the following copyright header Not pushing! But if the better RNG is already incorporated, why not be consistent and uniform. Just asking. Monte Carlo methods are more important every day, so best RNG is vital. Thanks! 

01262017, 07:49 AM
Post: #17




RE: Uniform Random Number Algorithm
It's not a technical issue, it's a legal issue.


« Next Oldest  Next Newest »

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