Repository navigation
r.surf.random: Draw from an exact random number layout - #8089
Merged
Merged
Conversation
Each row is a unit of an exact layout drawing one value per cell, so every row starts where it started in a serial run and the maps stay identical for a given seed, while the row loop no longer depends on the shared generator. The integer map takes G_random_uint32(), the bits G_mrand48() gave. 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 or silently reduced to its low 32 bits.
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 rows are still filled one after another, so a comment about getting the values of a serial run in any order does not apply yet. Written with the help of Claude Code.
The warning joined two complete clauses with a semicolon and had no final period. The style guide asks for periods after complete sentences, and most messages with two sentences use them. Written with the help of Claude Code.
wenzeslaus
force-pushed
the
r-surf-random-layout
branch
from
October 20, 2026 04:10
97f0fe7 to
e5905e2
Compare
petrasovaa
reviewed
Oct 21, 2026
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.
r.surf.random draws its values from a caller-owned random number state instead of the shared generator, with each row as one unit of an exact random number layout. The maps for a given seed are identical to earlier versions, and the seed is read with the standard function for the seed option.
This brings little new besides the unified seed handling, a warning for regions with more cells than one seed holds, and the use of the new API as an example. However, the cost is small, a few lines to manage the state. It is a first step towards making r.surf.random parallel.
Details (AI generated)
The change
G_random_state_for_unit()before the row is filled. The float map draws withG_random_double(). The integer map draws withG_random_uint32(), which returns what(unsigned int)G_mrand48()gave. Both maps are therefore byte-identical to earlier versions for a given seed.G_random_seed_from_option(), so a seed which is not wholly an integer or is outside -2147483648 to 4294967295 is an error naming the option, before the output exists. It was truncated withstrtol()before. 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
Float and integer maps for 8 seeds across the whole range 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.