Re: Re: RANDOM function?

From: ghaverla(at)freenet(dot)edmonton(dot)ab(dot)ca
To: macky <macky(at)edsamail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Re: RANDOM function?
Date: 2001-07-31 11:53:36
Message-ID: Pine.A41.3.95.1010731054631.47568A-100000@freenet.edmonton.ab.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


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.

Gord

Matter Realisations http://www.materialisations.com/
Gordon Haverland, B.Sc. M.Eng. President
101 9504 182 St. NW Edmonton, AB, CA T5T 3A7
780/481-8019 ghaverla @ freenet.edmonton.ab.ca
780/993-1274 (cell)

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Einar Karttunen 2001-07-31 12:58:24 Re: Re: RANDOM function?
Previous Message Einar Karttunen 2001-07-31 06:09:27 Re: RANDOM function?