Generate random values in OpenBOR script.
Load this library into your module projects to enable controllable random number generation.
Any DC library that lists DC D20 as a dependency may already include it.
This improves randomness by introducing human entropy into random generation.
Generate a random integer between lower and upper boundary.
Update the entropy seed. It is recommended to run this in the keyall event to add human entropy into random generation.
Get the current entropy seed without modifying it.
Load this library into your module projects to enable controllable random number generation.
Installation
- Download and unpack the library.
- Place the dc_d20 folder into your data/scripts folder.
- Add the following include to any script where you want to use this library:
C:
#include "data/scripts/dc_d20/main.c"
Any DC library that lists DC D20 as a dependency may already include it.
Optional: Add Player Input Entropy
Highly recommended: Add keyall.c to your data/scripts folder if it does not exist already. Include the library as above, then add the following code inside main():
C:
void main()
{
int player_index = getlocalvar("player");
int key_press = getplayerproperty(player_index, "keys");
int player_entropy = (player_index + 1) << 16;
/*
* Mix key state and player identity into the entropy seed.
* This helps player input influence future random values.
*/
dc_d20_update_entropy_seed(key_press ^ player_entropy);
}
This improves randomness by introducing human entropy into random generation.
Use Cases
Generate a random integer between lower and upper boundary.
C:
int lower_bound = 0;
int upper_bound = 10;
int i = dc_d20_generate_random_int(lower_bound, upper_bound);
Update the entropy seed. It is recommended to run this in the keyall event to add human entropy into random generation.
C:
int additional_entropy = 1;
int updated_seed = dc_d20_update_entropy_seed(additional_entropy);
Get the current entropy seed without modifying it.
C:
int entropy_seed = dc_d20_get_entropy_seed();