Ruby: include/ruby/internal/intern/random.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Functions
random.h File Reference

MT19937 backended pseudo random number generator. More...

`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`

Go to the source code of this file.

## Functions
unsigned int | rb_genrand_int32 (void)
double | rb_genrand_real (void)
void | rb_reset_random_seed (void)
VALUE | rb_random_bytes (VALUE rnd, long n)
VALUE | rb_random_int (VALUE rnd, VALUE max)
unsigned int | rb_random_int32 (VALUE rnd)
double | rb_random_real (VALUE rnd)
unsigned long | rb_random_ulong_limited (VALUE rnd, unsigned long limit)
unsigned long | rb_genrand_ulong_limited (unsigned long i)

## Detailed Description

MT19937 backended pseudo random number generator.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

See also
  Matsumoto, M., Nishimura, T., "Mersenne Twister: A 623- dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation, 8 (1): pp 3-30, 1998. https://doi.org/10.1145/272991.272995

Definition in file random.h.

## Function Documentation

## ◆ rb_genrand_int32()

unsigned int rb_genrand_int32 | ( | void |  | ) |

Definition at line 189 of file random.c.

References rb_random_mt_t::mt.

## ◆ rb_genrand_real()

double rb_genrand_real | ( | void |  | ) |

Definition at line 196 of file random.c.

References rb_random_mt_t::mt.

## ◆ rb_genrand_ulong_limited()

unsigned long rb_genrand_ulong_limited | ( | unsigned long | i | ) |

Definition at line 975 of file random.c.

References rb_random_mt_t::base.

## ◆ rb_random_bytes()

VALUE rb_random_bytes | ( | VALUE | rnd,
|  | long | n
| ) |  |

Definition at line 1205 of file random.c.

References NULL.

## ◆ rb_random_int()

VALUE rb_random_int | ( | VALUE | rnd,
|  | VALUE | max
| ) |  |

## ◆ rb_random_int32()

unsigned int rb_random_int32 | ( | VALUE | rnd | ) |

Definition at line 1004 of file random.c.

## ◆ rb_random_real()

double rb_random_real | ( | VALUE | rnd | ) |

Definition at line 1047 of file random.c.

References NUM2DBL, rb_eRangeError, rb_funcallv, rb_raise(), and TRUE.

## ◆ rb_random_ulong_limited()

unsigned long rb_random_ulong_limited | ( | VALUE | rnd,
|  | unsigned long | limit
| ) |  |

Definition at line 1107 of file random.c.

References NUM2ULONG, rb_eRangeError, rb_funcallv_public(), rb_num_negative_p(), rb_raise(), and rb_to_int().

## ◆ rb_reset_random_seed()

void rb_reset_random_seed | ( | void |  | ) |

Definition at line 1664 of file random.c.

References rb_random_mt_t::base, INT2FIX, rb_random_mt_t::mt, rb_random_struct::seed, and uninit_genrand.