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:
parent
71d0001f3d
commit
691f096c68
1 changed files with 7 additions and 0 deletions
|
@ -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 }
|
||||||
|
|
Loading…
Add table
Reference in a new issue