Re: random ints on symmetric interval
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: random ints on symmetric interval         

Group: comp.lang.fortran · Group Profile
Author: glen herrmannsfeldt
Date: Sep 16, 2008 23:36

Ron Ford wrote:
> I *do* have off by one bug, but I think we're both wrong at this point, as
> your classical way to roll a die has uneven outcomes.

All will have slightly uneven outcome unless i_tot evenly
divides the appropriate generator value, often the number
of possible return values and often a power of two. But...
> call random_number(harvest)
> b = min(max(1,ceiling(harvest*sides)),sides)

is different that the previously suggested:
>> b = -i_max + int( harvest * i_tot )

ceiling(harvest*sides) mostly returns a value between
1 and sides, with an extremely low probability of zero.

max(1,ceiling(harvest*sides)) the min doesn't do anything.

removes even that small probability. sides=t_tot=2*i_max+1,
the result is between 1 and 2*_max+1.
Later you subtract i_max, so between 1-imax and imax+1.

It seems you don't have bounds checking on, and you don't
notice the counts in k(i_max+1)

Either use floor() or int(), or subtract one.

As far as the original question, I believe it is
one fourth, not one eighth.

If you have two (approximately) symmetric distributions
uniform over, for example, the range (-1/2,1/2), that is,
the PDF is rect(x)

http://en.wikipedia.org/wiki/Rectangular_function

(Note that the result doesn't depend on rect(1/2) or rect(-1/2).)

The PDF of the difference is tri(x)

(the convolution of rect with itself)

http://en.wikipedia.org/wiki/Triangular_function

which has one fourth of its area outside (-1/2,1/2).

-- glen
no comments
diggit! del.icio.us! reddit!