GRASS 8 Programmer's Manual 8.6.0dev(2026)-51551cd856
Loading...
Searching...
No Matches
random_options.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/random_options.c
3 *
4 * \brief GIS Library - Random number seed from the option of a tool
5 *
6 * SPDX-FileCopyrightText: 2026 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include <stdint.h>
11
12#include <grass/gis.h>
13#include <grass/glocale.h>
14
15/*!
16 * \brief Read the random number seed from a seed option
17 *
18 * Call after G_parser() with an option which has an answer. The answer is
19 * read with G_random_parse_seed(); an answer which is not a seed is a
20 * fatal error naming the option. The parser itself checks an integer
21 * option only loosely, so this check is needed.
22 *
23 * The result is a seed accepted by G_random_state_from_seed(), the layout
24 * functions and G_srand48(). The function does nothing beyond parsing and
25 * checking: recording the seed, or generating one when the option is not
26 * given, is up to the tool.
27 *
28 * \param seed the seed option, usually G_OPT_M_SEED, whatever its key
29 *
30 * \return the seed, from -2^31 to 2^32 - 1
31 */
33{
34 int64_t value;
35 const char *problem;
36
37 if (!seed->answer)
38 G_fatal_error(_("%s= is required"), seed->key);
39 problem = G_random_parse_seed(seed->answer, &value);
40 if (problem)
41 G_fatal_error(_("Invalid random seed <%s> for %s=: %s"), seed->answer,
42 seed->key, problem);
43 return value;
44}
const char * G_random_parse_seed(const char *, int64_t *)
Read a random number seed from a text.
Definition lrand48.c:156
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
#define _(str)
Definition glocale.h:10
int64_t G_random_seed_from_option(const struct Option *seed)
Read the random number seed from a seed option.
Structure that stores option information.
Definition gis.h:562