Add info to documentation about random numbers, initialize srand (#2056)

Issue #2053 has highlighted the fact that random numbers are always generated with the same seed.
An example of generating different random numbers, other than the original seed, has been added to the documentation.
Furthermore srand initialization has been added to jerry-main, and targets.
Update test-common.h with srand call.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
This commit is contained in:
Daniel Balla
2017-11-03 15:31:57 +01:00
committed by László Langó
parent 678fcb20ed
commit 4690d128b3
9 changed files with 52 additions and 19 deletions
+1
View File
@@ -136,6 +136,7 @@ void eval_jerry_script (int argc, char *argv[], struct tcmd_handler_ctx *ctx)
void jerry_start ()
{
srand ((unsigned) jerry_port_get_current_time ());
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global_obj_val = jerry_get_global_object ();
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
+1
View File
@@ -24,6 +24,7 @@ static Serial pc (USBTX, USBRX); //tx, rx
static int jerry_task_init (void)
{
srand ((unsigned) jerry_port_get_current_time ());
int retcode;
DECLARE_JS_CODES;
@@ -67,6 +67,7 @@ static int load_javascript() {
}
int jsmbed_js_init() {
srand ((unsigned) jerry_port_get_current_time());
jerry_init_flag_t flags = JERRY_INIT_EMPTY;
jerry_init(flags);
@@ -97,6 +97,7 @@ const shell_command_t shell_commands[] = {
int main (void)
{
srand ((unsigned) jerry_port_get_current_time ());
printf ("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
printf ("This board features a(n) %s MCU.\n", RIOT_MCU);
+1
View File
@@ -79,6 +79,7 @@ static int shell_cmd_handler (char *source_buffer)
void main (void)
{
srand ((unsigned) jerry_port_get_current_time ());
uint32_t zephyr_ver = sys_kernel_version_get ();
printf ("JerryScript build: " __DATE__ " " __TIME__ "\n");
printf ("JerryScript API %d.%d\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);