In PHP
, can I get a set of random numbers which conform to a specified mean and standard deviation?
Asked
Active
Viewed 3,304 times
7

Peter O.
- 32,158
- 14
- 82
- 96

David Parks
- 30,789
- 47
- 185
- 328
-
From what type of distribution? Uniform? Normal? Something else? – Mark Byers Nov 12 '11 at 22:22
-
Choose a distribution first. There are an infinite number of ways that a set of numbers can conform to those criterion. – Blender Nov 12 '11 at 22:24
-
1Great points, I missed a detail, normal is normal enough for this purpose. – David Parks Nov 12 '11 at 22:31
1 Answers
7
The stats_rand_gen_normal
function will do exactly this. (Assuming you mean a normal distribution.)

David Schwartz
- 179,497
- 17
- 214
- 278
-
Well, had to manually patch it before compile to make it work (https://bugs.php.net/bug.php?id=57830), and now it just generates the same number each time I call it (the arch-nemesis of randomness, complete predictability). Any idea how this thing works? There are no docs. – David Parks Nov 12 '11 at 23:20
-
@DavidParks: There are several questions here that discuss how a function like that works on this page's sidebar, for example [this question](http://stackoverflow.com/questions/1626023/c-sharp-normal-random-number). – Peter O. Nov 12 '11 at 23:46
-
@DavidParks Show the part of your code that calls [`srand`](http://www.php.net/manual/en/function.srand.php). Your bug is likely there. – David Schwartz Nov 13 '11 at 00:04