Re: Re: RANDOM function?

From: Einar Karttunen macky , Re: Re: RANDOM function? 2001-07-31 12:58:24 Pine.LNX.4.33.0107311541140.19887-100000@melkinpaasi.cs.Helsinki.FI (view raw, whole thread or download thread mbox) 2001-07-31 05:41:43 from "macky"  2001-07-31 05:50:53 from Einar Karttunen   2001-07-31 05:55:28 from "macky"    2001-07-31 06:09:27 from Einar Karttunen    2001-07-31 11:53:36 from ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca     2001-07-31 12:58:24 from Einar Karttunen      2001-07-31 13:14:05 from ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca       2001-07-31 13:30:23 from Einar Karttunen      2001-07-31 13:22:59 from ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca     2001-07-31 13:19:15 from Neal Lindsay      2001-07-31 13:27:39 from Einar Karttunen       2001-07-31 13:58:21 from ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca        2001-07-31 14:09:07 from Einar Karttunen pgsql-novice
```On Tue, 31 Jul 2001 ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca wrote:

>
> On Tue, 31 Jul 2001, macky wrote:
>
> > if ill be using big range of numbers sa 10000 woundd the be any possibility
> > to have multiple items... meaning lets say 1234 will show up more than once?
>
> It sounds like you are trying to draw a number from a finite
> supply, WITHOUT REPLACEMENT.  I don't know how to attach
> an external C (perl, ...?) function to PostgreSQL, but
> I think you'll end up doing this.
>
> Some of what I am describing can be done "virtually".
> You will need to set up an array (stack, list) containing
> all the possible integers you want to draw from.  Say
> 1, 2, 3, .... 100000.  Note that there are 100000
> elements in the stack.  Now, draw a random (0 - 1)
> floating point number.  If the 0-1 deviate lies between
> (i-1)/N  and  i/N (where N is how many integers are in
> our stack, and i is an index), we will withdraw the
> i'th value from the stack as our random number (leaving
> us with N-1 values in the stack).  We continuous to
> withdraw numbers in this manner until we have either
> withdrawn enough numbers, or we have exhausted the stack.
>
That sounds very hard to implement effeciently. Could you send me some
high level pseudocode? I think that a with 31 bit random integers the
probablity to get the same value is very very small. If it is too big
I can always change to bigints.

- Einar Karttunen

```

pgsql-novice by date

 Next: From: ghaverla Date: 2001-07-31 13:14:05 Subject: Re: Re: RANDOM function? Previous: From: ghaverla Date: 2001-07-31 11:53:36 Subject: Re: Re: RANDOM function?