mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-07 21:18:05 +02:00
[script] Add a random number generator
Adds Math.Random() which returns a random number between 0 and 1.
This commit is contained in:
parent
d34694c1b9
commit
bef862fa92
1 changed files with 12 additions and 1 deletions
|
|
@ -44,7 +44,6 @@ static script_return_t script_lib_math_double_from_double_function (script_state
|
|||
return script_return_obj (script_obj_new_number (reply_double));
|
||||
}
|
||||
|
||||
|
||||
static script_return_t script_lib_math_double_from_double_double_function (script_state_t *state,
|
||||
void *user_data)
|
||||
{
|
||||
|
|
@ -55,6 +54,13 @@ static script_return_t script_lib_math_double_from_double_double_function (scrip
|
|||
return script_return_obj (script_obj_new_number (reply_double));
|
||||
}
|
||||
|
||||
static script_return_t script_lib_math_random (script_state_t *state,
|
||||
void *user_data)
|
||||
{
|
||||
double reply_double = random() / ((double)RAND_MAX + 1);
|
||||
return script_return_obj (script_obj_new_number (reply_double));
|
||||
}
|
||||
|
||||
static double double_to_int (double value)
|
||||
{
|
||||
return (double) (int) value;
|
||||
|
|
@ -102,6 +108,11 @@ script_lib_math_data_t *script_lib_math_setup (script_state_t *state)
|
|||
double_to_int,
|
||||
"value",
|
||||
NULL);
|
||||
script_add_native_function (math_hash,
|
||||
"Random",
|
||||
script_lib_math_random,
|
||||
NULL,
|
||||
NULL);
|
||||
script_obj_unref (math_hash);
|
||||
|
||||
data->script_main_op = script_parse_string (script_lib_math_string, "script-lib-math.script");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue