![]() | Fun 0.41.5 The programming language that makes You have fun |
Implements the OP_RANDOM_INT opcode for generating random integers in the VM. More...
Go to the source code of this file.
Functions | |
| if (lo.type !=VAL_INT||hi.type !=VAL_INT) | |
| if (b<=a) | |
| push_value (vm, make_int(a+r)) | |
| free_value (lo) | |
| free_value (hi) | |
Variables | |
| case | OP_RANDOM_INT |
| Value | lo = pop_value(vm) |
| int64_t | a = lo.i |
| int64_t | b = hi.i |
| int64_t | span = b - a |
| int64_t | r = (int64_t)(rand() % (span)) |
| break | |
Implements the OP_RANDOM_INT opcode for generating random integers in the VM.
This file handles the OP_RANDOM_INT instruction, which generates a random integer within a specified range. The range bounds are popped from the stack, and the result is pushed back.
Behavior:
Error Handling:
Example: // Bytecode: OP_RANDOM_INT // Stack before: [10, 1] // Stack after: [7]
Definition in file random_int.c.
| free_value | ( | hi | ) |
| free_value | ( | lo | ) |

| if | ( | b<= | a | ) |
Definition at line 36 of file random_int.c.
| int64_t a = lo.i |
Definition at line 40 of file random_int.c.
| int64_t b = hi.i |
Definition at line 40 of file random_int.c.
| break |
Definition at line 52 of file random_int.c.
| Value lo = pop_value(vm) |
Definition at line 35 of file random_int.c.
| case OP_RANDOM_INT |
Definition at line 33 of file random_int.c.
| int64_t r = (int64_t)(rand() % (span)) |
Definition at line 48 of file random_int.c.
Definition at line 47 of file random_int.c.