Skip to content

Conversation

lesquoyb
Copy link
Contributor

Work in progress to answer #419 by using more appropriate methods to draw random numbers in certain cases.
Also will tackle the lack of flexibility of setting the variable rng_usage.
And at the same time will provide a comprehensive unit test file to cover the use of random operators in gama

- very incomplete but the missing parts are documented in the comments
- creates nextInt(int) and nextInt(int, int) methods in IGamaRNG
- removes unused nextInt() to avoid confusion
- some inlined comments about future work to come
@AlexisDrogoul AlexisDrogoul self-requested a review March 2, 2025 02:19
for (long i = 0; i < usage; i++) { nextInt(); }
//TODO: If nextInt(nb) with nb a power of 2 we draw less than if not
// but this doesn't reflect on the rng_usage
for (long i = 0; i < usage; i++) { nextInt(32); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why calling nextInt(32) ?

Copy link
Contributor Author

@lesquoyb lesquoyb Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is poorly explained in the comment above: calling it with a number of bit that is not a power of 2 results in more than one draw which is not what we want to achieve here.
See the implementation of nextInt(int) called by in Random.class itself called by GamaRNG:
image
There's a TODO because I do not like the idea of having to take into account the specificities of certain implementation and I'd prefer to have a nextState function or something similar instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants