| get_seed | R Documentation |
Functions for recovering the original seed value that produced the current random number generator state. Provides both R and C++ implementations with the C++ version offering significantly improved performance for large search spaces.
get_seed(range = NULL, fallback_seed = 42, max_search = 2147483647,
step_size = 50000, use_cpp = TRUE, ...)
get_seed_cpp(range = NULL, fallback_seed = 42, max_search = 2147483647,
step_size = 50000, batch_size = 10000, verbose = TRUE)
range |
Optional integer vector of specific seed values to search. If provided, only these seeds will be tested instead of systematic range searching. |
fallback_seed |
Integer seed value to return if no matching seed is found during the search process (default: 42). |
max_search |
Maximum seed value to search up to when performing systematic range searching. Must be a positive integer within the valid range for R's random number generator (default: 2147483647). |
step_size |
Step size for systematic range searching when no specific range is provided. Larger values speed up search but may miss the target seed if it falls between steps (default: 50000). |
use_cpp |
Logical; if |
batch_size |
Integer specifying the number of seeds to process in each C++ batch operation. Larger batches are more memory efficient but require more RAM. Only used in |
verbose |
Logical; if |
... |
Additional arguments passed to |
The functions work by systematically testing seed values to find one that reproduces the current RNG state stored in .Random.seed. The search process:
Tests each candidate seed by setting it and comparing the resulting RNG state
Uses efficient C++ implementation for faster processing of large search spaces
Supports both targeted searching (via range parameter) and systematic range searching
Employs batched processing to optimize memory usage and performance
Performance Considerations:
The C++ implementation (get_seed_cpp()) provides significant performance improvements:
Batch processing reduces overhead for large search spaces
Optimized memory management prevents excessive RAM usage
Native C++ random number generation matching R's implementation
Progress reporting for long-running searches
Search Strategy:
If range is provided: Tests only the specified seed values
If range is NULL: Performs systematic search from 1 to max_search in steps of step_size
Search terminates immediately when a matching seed is found
Returns fallback_seed if no match is found within the search parameters
Memory Management:
The C++ implementation uses batched processing controlled by batch_size to:
Process large search ranges without excessive memory allocation
Provide regular progress updates during long searches
Allow interruption of long-running operations
Returns an integer representing the seed value that reproduces the current random number generator state.
If no matching seed is found within the search parameters, returns the fallback_seed value.
Requires an active RNG state (i.e., .Random.seed must exist)
Large search ranges may take considerable time even with C++ optimization
The search is deterministic but computationally intensive
Consider using smaller step_size values if the initial search fails
set.seed, .Random.seed
## Basic seed recovery after generating random numbers
set.seed(123)
recovered_seed <- get_seed()
print(recovered_seed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.