[m-users.] The new random module(s)

Julian Fondren jfondren at minimaltype.com
Thu Sep 5 14:30:48 AEST 2019

Hello list,

With a recent rotd you may notice some new warnings:

   Warning: call to obsolete predicate `random.init'/2.

This module now offers a typeclass and several random number generators.
That's very cool!  Using typeclasses and multiple generators is the very
first thing I wanted to fix with Mercury's stdlib, some years ago before
I got pulled into other things instead.

One benefit to the new code is that you don't need to use the FFI (or
read from a random device) just to get a random seed.

But my code is still a little weird:

   main(!IO) :-
       random.generate_uint64(Seed, random.sfc16.init, _), % new stuff
       random.init(uint64.cast_to_int(Seed), RS),          % old stuff
       fifteen.shuffled(Board, RS, _),

Why the mix?  array.random_permutation and random.permutation have been
left behind, and only work with a random.supply.

The change also means that I'll have to add a "works with" version
warning to this code when I submit it to RosettaCode, since it'll fail
with 14.01.

More information about the users mailing list