boo1ean / casual

Fake data generator for javascript
3.03k stars 152 forks source link

integer generator is noticeably biased away from the ends of the range #88

Open robinmessage opened 5 years ago

robinmessage commented 5 years ago

The casual.integer generator is noticeably biased away from the ends of the range; the start and end of the range only occur with half the frequency of the other elements.

The reason for this is the use of Math.round and a range of to-from, which is not big enough. A better formula might be:

Math.floor(from + (to - from + 1) * this.random)

Of course, this would break anyone who is depending on the same answers with the same seed, so maybe a new method would be better?