What distribution does the numbers generated using rand() function in C language follow? Is it guassian / uniform etc..
What is the distribution followed by the numbers generated using rand() function in C language?
Like rand uses between 0 and 1, and all real numbers in between have the same probability to appear the distribution is uniform. If it were not the case then the numbers generated could not be named "random".
Reply:• The rand function generates random integers between 0 and
RAND_MAX.
• The only requirement specified by the ANSI C standard is that
RAND_MAX must be at least 32767.
• ANSI C standard permits that the calculation method may
vary.
• However, pseudo-random numbers generated by rand() are in
fact as shown below (example for Visual C++), as in the case
of numbers based on the linear congruence method).
x1 = 1 (This is the seed. It can be changed using srand().)
xn≡ 214013 ∗ xn-1 + 2531011 mod 231
X = Integer portion of (xn/216) (0 %26lt; X %26lt; 215)
Reply:The rand() function returns a integer between 0 and RAND_MAX (usually 32767).
The code (and variants) are shown and explained here:
Reply:The implementation varies by platform thus the distribution would as well. The implementation based on the CPU clock should be Poisson or Weibull; implementation based on pregenerated data could be anything.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment