Using the Raised Cosine Distribution in PRNG - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: General Forum ( /forum-4.html)+--- Thread: Using the Raised Cosine Distribution in PRNG ( /thread-7440.html) |

Using the Raised Cosine Distribution in PRNG - Namir - 12-18-2016 01:51 AM
The Raised Cosine Distribution provides tool for a simple non-uniform PRNG. The equation for the cumulative probability function is: CDF = [1 + xs + sin(pi*xs)/pi]/2 Where xs = (x-m)/s and m is the mean and s is the spread. Choosing m = s = 0.5 makes the CDF curve map values from the range (0, 1) to values in the range (0, 1). This special mapping allows us to skip the traditional approach where we assign a uniform random number to CDF and solve for x (which requires using an iterative method). Instead we can cheat and use the above equation by assigning a uniform random number to x and calculate the CDF as the specialized random number. The distribution of the random number generated form a U shaped distribution. So to make your games interesting, test for values generated around 0.5 (say the range (0.45, 0.55)) to trigger game events. The recommended range is less likely to occur than values near 0 or 1. I know that my suggestion is heretical, but it works!! Namir RE: Using the Raised Cosine Distribution in PRNG - mark4flies - 12-21-2016 01:42 PM
I ever heard of this distribution. What is it used to model? RE: Using the Raised Cosine Distribution in PRNG - Namir - 12-21-2016 03:20 PM
(12-21-2016 01:42 PM)mark4flies Wrote: I ever heard of this distribution. What is it used to model? I think it's a quick and rough approximation for Normal Gaussian distribution. Namir RE: Using the Raised Cosine Distribution in PRNG - mark4flies - 12-25-2016 12:30 PM
Thanks! I agree with the "rough" performance assessment. Would not serve serious applications that require PRNG. But a game would not suffer while enjoying the speed. RE: Using the Raised Cosine Distribution in PRNG - ttw - 12-26-2016 01:37 AM
Another distribution (probably suitable for gaming but not for high-accuracy calculation without some extra work) that mimics the normal is the Kahn Pseudo Normal. It's easy to generate. With u being uniformly distributed between 0 and 1, the variates are given by: Y = Log ( 1/u - 1 ) Another possibility, but with infinite variance: Y = Tangent( Pi * (Y - 1/2) ) Averages of the first distribution converge to a normal distribution (central limit theorem). Averages of the second distribution converge to another Cauchy distribution. RE: Using the Raised Cosine Distribution in PRNG - Paul Dale - 12-26-2016 01:42 AM
For exact normal distribution samples from uniforms use the Box–Muller transform. Two independent uniform samples in, two independent normal samples out. Pauli RE: Using the Raised Cosine Distribution in PRNG - Namir - 12-26-2016 02:12 AM
(12-26-2016 01:42 AM)Paul Dale Wrote: For exact normal distribution samples from uniforms use the Box–Muller transform. The Raised Cosine Distribution uses just one call to a trig function per pseudo-random number. No need for calling ln(x) or sqrt(x) as is the case with the Box-Muller method. Granted that this method requires straight forward calculations. Namir RE: Using the Raised Cosine Distribution in PRNG - Paul Dale - 12-26-2016 07:39 AM
On calculators that support it: \( RAND \\ \phi^{-1}\) works really well. It might even be faster than the programme steps for the raised cosine distribution -- depending on the approximation used for \( \phi^{-1}\) Pauli RE: Using the Raised Cosine Distribution in PRNG - Namir - 12-26-2016 11:03 AM
(12-26-2016 07:39 AM)Paul Dale Wrote: On calculators that support it: That's an offer I can't refuse!! :-) RE: Using the Raised Cosine Distribution in PRNG - Dieter - 12-26-2016 08:01 PM
(12-26-2016 07:39 AM)Paul Dale Wrote: On calculators that support it: If you refer to the 34s: The Normal quantile is evaluated by an initial first guess which is then refined in one or (at most) two iterations. Since every iteration calls the Incomplete Gamma function which is a bit slow for arguments > √3, a faster simplified approach could be used that only applies the first guess to the random number. At least for the suggested application in games this should be sufficiently exact. But the Normal guess routine is not exposed to the user so the suggested method is not applicable. At least not directly. ;-) Dieter |