1
0
Fork 0

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.
This commit is contained in:
curt 2006-01-09 15:29:24 +00:00
parent 71d0001f3d
commit 691f096c68

View file

@ -288,6 +288,12 @@ static naRef f_rand(naContext c, naRef me, int argc, naRef* args)
return naNum(sg_random()); 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 // Wrapper function for screenPrint
static naRef f_screenPrint(naContext c, naRef me, int argc, naRef* args) 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 }, { "_cmdarg", f_cmdarg },
{ "_interpolate", f_interpolate }, { "_interpolate", f_interpolate },
{ "rand", f_rand }, { "rand", f_rand },
{ "srand", f_srand },
{ "screenPrint", f_screenPrint }, { "screenPrint", f_screenPrint },
{ "directory", f_directory }, { "directory", f_directory },
{ 0, 0 } { 0, 0 }