Re: pgbench - add pseudo-random permutation function - Mailing list pgsql-hackers

From Fabien COELHO
Subject Re: pgbench - add pseudo-random permutation function
Date
Msg-id alpine.DEB.2.22.394.2103311933490.620883@pseudo
Whole thread Raw
In response to Re: pgbench - add pseudo-random permutation function  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: pgbench - add pseudo-random permutation function
List pgsql-hackers
Hello Dean,

> OK, attached is an update making this change and simplifying the rotate 
> code, which hopefully just leaves the question of what (if anything) to 
> do with pg_erand48().

Yep. While looking at it, I have some doubts on this part:

  m = (uint64) (pg_erand48(random_state.xseed) * (mask + 1)) | 1;
  r = (uint64) (pg_erand48(random_state.xseed) * (mask + 1));
  r = (uint64) (pg_erand48(random_state.xseed) * size);

I do not understand why the random values are multiplied by anything in 
the first place…

This one looks like a no-op :

    r = (uint64) (pg_erand48(random_state.xseed) * size);
    v = (v + r) % size;

    v = (v + r) % size
      = (v + rand * size) % size
      =? (v % size + rand * size % size) % size
      =? (v % size + 0) % size
      = v % size
      = v

I'm also skeptical about this one:

    r = (uint64) (pg_erand48(random_state.xseed) * (mask + 1));
    if (v <= mask)
       v = ((v * m) ^ r) & mask;

    v = ((v * m) ^ r) & mask
      = ((v * m) ^ r) % (mask+1)
      = ((v * m) ^ (rand * (mask+1))) % (mask+1)
      =? ((v * m) % (mask+1)) ^ (rand * (mask+1) % (mask+1))
      =? ((v * m) % (mask+1)) ^ (0)
      = (v * m) & mask

Or possibly I'm missing something obvious and I'm wrong with my 
arithmetic?

-- 
Fabien.

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: pg_amcheck contrib application
Next
From: Joe Conway
Date:
Subject: Re: "has_column_privilege()" issue with attnums and non-existent columns