From 691f096c68d9437ac1adf01a94dbd14b819f7b99 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 9 Jan 2006 15:29:24 +0000 Subject: [PATCH] Add an srand() function to nasal (hooked into sg_srandom_time()). This helps avoid the problem of always getting the same random number sequence every time you run a script. --- src/Scripting/NasalSys.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 41de581a6..4bbe08295 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -288,6 +288,12 @@ static naRef f_rand(naContext c, naRef me, int argc, naRef* args) return naNum(sg_random()); } +static naRef f_srand(naContext c, naRef me, int argc, naRef* args) +{ + sg_srandom_time(); + return naNum(0); +} + // Wrapper function for screenPrint static naRef f_screenPrint(naContext c, naRef me, int argc, naRef* args) { @@ -327,6 +333,7 @@ static struct { char* name; naCFunction func; } funcs[] = { { "_cmdarg", f_cmdarg }, { "_interpolate", f_interpolate }, { "rand", f_rand }, + { "srand", f_srand }, { "screenPrint", f_screenPrint }, { "directory", f_directory }, { 0, 0 }