0
$\begingroup$

As part of an assignment I have to write a PRNG using a sin (or any other trigonometric function) and a saw function which I'm struggling a bit with. So how would you find a good saw function with about equal distribution?

This is what it is supposed to look like: enter image description here

There are two functions I've got now,

y=(seed/1000*state*49) mod 101 and

z=(y-1 % 10) / 10)

and distribution looks like this (I'm not fine with that 1 and 0 distribution):

enter image description here

$\endgroup$
1
$\begingroup$

I think this is an effect of the rounding in your implementation or in the histogram.

Let's say your histogram contains 100 columns. Each represents a width of 0.01. The column at 10 shows how many items fall between 9.995 and 10.005. The column at 0 shows how many items fall between -0.005 and 0.005. However, there are no items below 0, so there is nothing between -0.005 and 0. This column will only show halve of the items in the other columns.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy