Re: random number problem
From: Ricardo Gibert (nospamgibert_at_cox.net)
Date: 07/09/04
- Next message: RobertMaas_at_YahooGroups.Com: "Re: what does "serialization" mean?"
- Previous message: Nick Landsberg: "Re: Was: what does "serialization" mean?"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Reply: rossum: "Re: random number problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 9 Jul 2004 11:31:42 -0700
<Jens.Toerring@physik.fu-berlin.de> wrote in message news:2l845qF9e8jmU2@uni-berlin.de...
> copx <invalid@invalid.com> wrote:
>
> > <Jens.Toerring@physik.fu-berlin.de> schrieb im Newsbeitrag news:2l811pF9vdpkU1@uni-berlin.de...
> >> copx <invalid@invalid.com> wrote:
> >> > I need a routine that returns a random integer number
> >> > between A and B including A and B (r >= A && r <= B).
> >> > That would be simple but I've an additional requirement:
> >> > The chance of all possible return values must be equal.
> >>
> >> That's what typical random generators are meant for -
> >> they should return numbers uniformly distributed over
> >> the whole interval.
>
> > Of course the number created by the PRNG is uniformly distributed.
> > But to create a random_int(min,max) function I need to apply
> > some additional calculations. Most PRNGs I know return
> > a float between 0 and 1. IIRC to create a function like I need
> > you would do something like
>
> > random_int = (rand() * max) + min
>
> > And I think this additional step destroys the uniformity..
>
> Why should it do that? It's a simple linear transformation.
> If you have uniformly distributed points drawn on an elastic
> band and then stretch it they stay uniformly ditributed.
> And a simple multiplication does nothing else (and adding an
> offset doesn't change anything).
The linear transformation maps from one interval to another. If the smaller number of elements of the one interval does not divide
evenly into the larger number of elements of other, then there will necessarily be some bias. When the number of elements you map
onto is a great deal smaller, then the bias is small enough to be ignored. This is usually the case, but when it is not, this is
usually overlooked with poor results as a consequence.
...
- Next message: RobertMaas_at_YahooGroups.Com: "Re: what does "serialization" mean?"
- Previous message: Nick Landsberg: "Re: Was: what does "serialization" mean?"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Next in thread: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: random number problem"
- Reply: rossum: "Re: random number problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|