7

In PHP, can I get a set of random numbers which conform to a specified mean and standard deviation?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
David Parks
  • 30,789
  • 47
  • 185
  • 328

1 Answers1

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