Random Numbers

This module provides pseudo-random number generators and random distributions.


Get pseudo-random number generator.

  • args (table) – keyword arguments
  • args.memory (string) – host or gpu (default: compute device)
  • args.seed (number) – initial seed value (optional)

pseudo-random number generator

The first call for each memory argument constructs a singleton instance of the pseudo-random number generator, which is returned in subsequent calls.

If the argument seed is omitted, the initial seed is obtained from the system’s random device, e.g., /dev/urandom on Linux.


Set (or reset) the seed of the pseudo-random number generator.


Return randomly shuffled sequence. The sequence is given as a Lua table.

The method is only available if the random number generator was constructed with memory = "host".