Repository navigation
v.random: Draw from a random number state of its own - #8094
Merged
Merged
Conversation
The points come from a single sequence seeded with G_random_state_from_seed(), which gives exactly the values the shared generator gave, so every case, including the rejection loops for restricted areas, keeps its points for a given seed. The seed is read with G_random_seed_from_option(), which refuses what is not wholly an integer or is outside the range the generator uses, instead of the seed being truncated to int by atoi(), and it is checked before the output map is created.
A seed out of range or with text after the integer is an error, and no map is created. The test covers the values beyond both ends of the range G_random_seed_from_option() accepts and a value with trailing text. Written with the help of Claude Code.
The comment only says what the placement of the code shows. Written with the help of Claude Code.
ToolError is what grass.tools raises. Its parent CalledModuleError is kept for code moving from run_command-style calls, and new code should not rely on it. Written with the help of Claude Code.
petrasovaa
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With this PR, v.random draws its points from a caller-owned random number state instead of the generator shared by the whole program. The state is a single sequence seeded with
G_random_state_from_seed(), which gives the same values as the shared generator. So every case, including the rejection loops for restricted areas, keeps its points for a given seed.The seed is now read with the standard function for the seed option. Previously, the text of the seed was converted with
atoi(), which ignored any text after the number and did not check the range.Details (AI generated)
The change
struct G_random_stateseeded from the seed replaces the function pointer toG_drand48(). The points and the rejection loops now draw from it.G_random_seed_from_option(). A seed which is not wholly an integer or is outside -2147483648 to 4294967295 is an error naming the option, reported before the output map is created. Previously,atoi()ignored trailing text and did not check the range. Without the option, a seed is generated withG_random_generate_seed(), as before.Tests
A test checks that a seed beyond each end of the range and a seed with trailing text are refused and that no map is created. The pinned-value tests of the tool already on main pass with the change.
Verification
2D and 3D points for 9 seeds across the whole range and points restricted to an area for 2 seeds were identical to those of the binary before this change.
Suggested squash commit message
The code and this description were written with Claude Code (Claude Fable 5.1 and Claude Opus 5.5) and reviewed by the author of the PR.