GRASS 8 Programmer's Manual 8.6.0dev(2026)-51551cd856
Loading...
Searching...
No Matches
random_options.c File Reference

GIS Library - Random number seed from the option of a tool. More...

#include <stdint.h>
#include <grass/gis.h>
#include <grass/glocale.h>
Include dependency graph for random_options.c:

Go to the source code of this file.

Functions

int64_t G_random_seed_from_option (const struct Option *seed)
 Read the random number seed from a seed option.
 

Detailed Description

GIS Library - Random number seed from the option of a tool.

SPDX-FileCopyrightText: 2026 GRASS Development Team SPDX-License-Identifier: GPL-2.0-or-later

Definition in file random_options.c.

Function Documentation

◆ G_random_seed_from_option()

int64_t G_random_seed_from_option ( const struct Option *  seed)

Read the random number seed from a seed option.

Call after G_parser() with an option which has an answer. The answer is read with G_random_parse_seed(); an answer which is not a seed is a fatal error naming the option. The parser itself checks an integer option only loosely, so this check is needed.

The result is a seed accepted by G_random_state_from_seed(), the layout functions and G_srand48(). The function does nothing beyond parsing and checking: recording the seed, or generating one when the option is not given, is up to the tool.

Parameters
seedthe seed option, usually G_OPT_M_SEED, whatever its key
Returns
the seed, from -2^31 to 2^32 - 1

Definition at line 32 of file random_options.c.

References _, G_fatal_error(), and G_random_parse_seed().