From 21219e65a459081c94616a5608d74564b69e91b4 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 17 Nov 2014 11:20:38 -0500 Subject: [PATCH] lib/math: documents `srand` and `srand_from` Signed-off-by: Jean Privat --- lib/standard/math.nit | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/standard/math.nit b/lib/standard/math.nit index 9d2b2bf..2bbb6aa 100644 --- a/lib/standard/math.nit +++ b/lib/standard/math.nit @@ -187,5 +187,22 @@ end fun atan2(x: Float, y: Float): Float is extern "kernel_Any_Any_atan2_2" fun pi: Float is extern "kernel_Any_Any_pi_0" + +# Initialize the pseudo-random generator with the given seed. +# The pseudo-random generator is used by the method `rand` and other to generate sequence of numbers. +# These sequences are repeatable by calling `srand_from` with a same seed value. +# +# ~~~~ +# srand_from(0) +# var a = 10.rand +# var b = 100.rand +# srand_from(0) +# assert 10.rand == a +# assert 100.rand == b +# ~~~~ fun srand_from(x: Int) is extern "kernel_Any_Any_srand_from_1" + +# Reinitialize the pseudo-random generator used by the method `rand` and other. +# This method is automatically invoked at the begin of the program, so usually, there is no need to manually invoke it. +# The only exception is in conjunction with `srand_from` to reset the pseudo-random generator. fun srand is extern "kernel_Any_Any_srand_0" -- 1.7.9.5