[m-users.] Random Number Generator

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Jul 31 23:28:35 AEST 2023


On 2023-07-31 14:33 +02:00 CEST, "Julien Fischer" <jfischer at opturion.com> wrote:
> The dummy variable is necessary because otherwise you couldn't create
> instances of the urandom type class.  Also, for some random number
> generators, it is not a dummy variable (e.g. on some systems the
> system_rng handle contains the file descriptor used to open /dev/urandom
> etc.)

I think a clearer explanation would put those things
in the reverse order:

1. Some kinds of random number generators, such as system_rng,
   need to carry around a data structure, such as the file descriptor
   for /dev/urandom, that (unlike the usual state of random number
   generators) does not change when you create a new random number.

2. Since some rngs have this extra argument, the urandom type class
   has to have this extra argument.

3. Rngs that don't need this extra argument then get to pass around
    a value of a dummy type as this extra argument.

This does bring up what I think is the root issue raised by the original
question, which is: given that the urandom type class could be designed
without this extra argument (since its instances could include
the info that is now in the extra argument in the rng state instead),
why wasn't that design chosen?

I wasn't involved in the design process of that type class, though I do
remember that there was significant discussion on related issues among
the interested Mercury developers, mainly Julien and Mark. A search of
my mailbox shows that this was in August 2019, but the m-rev archive
for that month does not show any discussion of this extra argument.
This suggests to me, though it does not prove, that this other design
was not really considered, at least at that time.

Zoltan.


More information about the users mailing list