|
PowerBASIC Forums
![]() Programming
![]() Random Number Generation Questions
|
| next newest topic | next oldest topic |
| Author | Topic: Random Number Generation Questions |
|
Roger Rines Member |
Random Number Generation Question In our project, we are using RND & Randomizer in a Monte Carlo simulation where we are looking at ways to generate synthetic market information that can be used in a testing engine used to trade the markets. In our project we need to understand the period of the Random Number Generator when it is in Floating Point mode. Here is what is listed in the HELP file: quote: With that statement I can't help but wonder how the length or value of the Seed fed to the Randomizer impacts the period. Is this information available? In Integer Mode the range of numbers generated is constrained by the Min & Max values passed to the RND command at execution and this is exactly what is needed in some places in the code. In other places, the code needs to use the RND command in Floating Point mode so the range of values will be constrained between 0 & 1. When the RND is used in different modes in the same process, are there any issues I need to understand so I won't bias the output. For example, does each RND process need a separate thread, or will they play well together? In checking the output from the RND process, the distribution of numbers follows a fairly good Centered Single Mode distribution. Is there a way to create a biased distribution with the RND process? If not, does anyone know of any PB code that could be used to create a non-centered distribution where the Skewness can be influenced? ------------------ Roger... (Mail to rdrines at SpamCop dot Net) [This message has been edited by Roger Rines (edited April 28, 2005).] IP: Logged |
|
Paul Dixon Member |
Roger, PB's random numbers have a period of 2^32. There are longer random number sequences, if you want them, in the source code forum. <<how the length or value of the Seed fed to the Randomizer impacts the period>> The period is 2^32. The seed sets the point within that 2^32 numbers from which to start. The period remains 2^32 regardless of which point yo start.. unless you keep reseeding which is usually not a good idea. Paul. ------------------ IP: Logged |
|
Trevor Ridley Member |
To bias the random distribution, I'm sure there are many statistically acceptable ways to do this. One empirical method that I use is as follows (in pseudo-code): R1 = random number between 0 and 1 (for example) This skews the distribution of R1 towards the lower end of its range. You can influence the amount of skew by fiddling with the range of R2. If you set R2 to a constant, it will bias the distribution more significantly towards that number. If you need more precise statistical control over the distribution - as opposed to my empirical "that looks OK for what I want" approach - I wouldn't recommend this solution! ------------------ [This message has been edited by Trevor Ridley (edited April 29, 2005).] IP: Logged |
|
Knuth Konrad Member |
Another PRNG source is available at http://www.infoms.com/bsp/list7-10.zip This is the (PB/DOS) source code to the Basically Speaking RNG article published in issue 07/1998. Knuth ------------------ IP: Logged |
|
Emil Menzel Member |
There is quite a lot of info on random number generators in these forums. A recent post of my own is titled "A Swiss Army random number generator" and it allows you to use any number of different generators. Greg Turgeon's post of the Mersenne Twister generator might be of particular interest to you, as this generator is very highly rated for Monte Carlo applications and has an extremely long period. Getting various distributions of numbers isn't a job for the The code is for PBCC but it should easily be translatable into I don't have a similar function on hand for controlling skew,
------------------ IP: Logged |
|
Roger Rines Member |
Thanks guys, you've provided many of the answers I was looking for, and I just discovered my version of Greg Turgeon's code was ancient. I've since updated it and will see if I can make it fit into the Monte Carlo simulation project after testing. I also discovered a lot of other postings by Greg Turgeon that are great items. I especially like the references in the postings and really Knuth, ------------------ IP: Logged |
|
Emil Menzel Member |
Roger: This might be no more than what Trevor was talking about; I
------------------ [This message has been edited by Emil Menzel (edited April 29, 2005).] IP: Logged |
|
Roger Rines Member |
Thanks Emil! This is similar to what I had tried. However, in my case In thinking about my approach, I now am beginning to think if I Your example will be a good reflection to use when I compare it Thank you for taking the time to make and send it. ------------------ IP: Logged |
|
Emil Menzel Member |
Now how did I forget this reference? It describes how to generate random numbers from almost any sort of distribution anyone ever thought of. http://www.gnu.org/software/gsl/manual/gsl-ref_19.html I only wish it were easier reading & that the software was in ------------------ IP: Logged |
|
Roger Rines Member |
Thanks Emil, Your link reference is a great resource. There are distributions on I hadn't seen this reference previously, so it should keep me busy Thanks for taking the time on this thread. ------------------ IP: Logged |
|
Emil Menzel Member |
Roger: It was fun, not a chore. If you learn how to link the libraries to PB, let me know. No reply needed. I'm headed for the Gulf Shore very shortly. Emil ------------------ IP: Logged |
|
Knuth Konrad Member |
Roger,
quote: The article was published on paper in Basically Speaking. I don't know if it is still possible to order back copies. I translated it to German (with the permission of the author) and published it on my web site: http://www.softaware.de/rng.htm There's a link to the original author (Jeff C. Jacobs) in that article, look for the link called "Email". Don't know if that address still works, though. Two links that might be of interest, mentioned in the article: Knuth ------------------ IP: Logged |
All times are EasternTime (US) | next newest topic | next oldest topic |
![]() |
|
Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.