From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
---|---|
To: | David Bowen <dmb0317(at)gmail(dot)com> |
Cc: | Bruce Momjian <bruce(at)momjian(dot)us>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Hironobu SUZUKI <hironobu(at)interdb(dot)jp>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: pgbench - add pseudo-random permutation function |
Date: | 2021-03-11 19:34:57 |
Message-ID: | CAEZATCVmqTUOhdhiLP7X9g7ZL-j0XGRY6z+TrnZeq0UfpCSG1A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, 11 Mar 2021 at 19:06, David Bowen <dmb0317(at)gmail(dot)com> wrote:
>
> The algorithm for generating a random permutation with a uniform distribution across all permutations is easy:
> for (i=0; i<n; i++) {
> swap a[n-i] with a[rand(n-i+1)]
> }
>
> where 0 <= rand(x) < x and a[i] is initially i (see Knuth, Section 3.4.2 Algorithm P)
>
True, but n can be very large, so that might use a lot of memory and
involve a lot of pre-processing.
Regards,
Dean
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-03-11 19:45:58 | Re: libpq debug log |
Previous Message | Robert Haas | 2021-03-11 19:34:03 | Re: pg_amcheck contrib application |