r.random(1)

โœจ r.random(1) โœจ

okay bestie, welcome to r.random, a certified GRASS GIS User's Manual banger ๐Ÿ’– she makes randomly placed raster cells AND vector points, like a little chaos gremlin with a purpose. She creates a raster map and vector point map containing randomly located cells and points. no cap.


๐ŸŒˆ KEYWORDS ๐ŸŒˆ

raster, sampling, vector, random, level1


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

r.random
r.random --help
r.random [-snzb] input=name  [cover=name]  npoints=number[%]
[raster=name]   [vector=name]   [seed=integer]   [--overwrite]  [--help]
[--verbose]  [--quiet]  [--ui]

โœจ Flags โœจ

  • -s โ€” Generate random seed (heads up, the result is non-deterministic ๐Ÿ’€)
  • -n โ€” Generate points also for NULL cells
  • -z โ€” Generate vector points as 3D points. Input raster values will be used for Z coordinates
  • -b โ€” Do not build topology. Do not build topology for vector points
  • --overwrite โ€” Allow output files to overwrite existing files
  • --help โ€” Print usage summary
  • --verbose โ€” Verbose module output
  • --quiet โ€” Quiet module output
  • --ui โ€” Force launching GUI dialog

๐ŸŒธ Parameters ๐ŸŒธ

  • input=name [required] โ€” Name of input raster map
  • cover=name โ€” Name of cover raster map
  • npoints=number[%] [required] โ€” The number of points (or cells) to generate. The number of vector points or raster cells to generate, possibly as a percentage of number of cells
  • raster=name โ€” Name for output raster map
  • vector=name โ€” Name for output vector map
  • seed=integer โ€” Seed for rand() function

๐Ÿ’… DESCRIPTION ๐Ÿ’…

The module r.random creates a raster map with values in random places. Or, if that's not your vibe, it creates random vector points at these places instead. The number of random cells or points can be a fixed number or a percentage of cells from the input. By default, generated cells or points will be a subset of non-NULL cells of the input. And the resulting raster map? It consists of original cell values at the selected random locations, and NULL (no data) values everywhere else. it's giving โœจselectiveโœจ.

๐Ÿฆ‹ Placement of cells and points ๐Ÿฆ‹

The module lets you create a raster map and/or a vector points map containing coordinates of points whose locations have been randomly determined. The module places these randomly generated vector points within the current computational region and raster mask (if any), on non-NULL raster cells in a user-specified raster map. If you set the -n flag, points will be randomly generated across all cells (even those with NULL values). Cells in the resulting raster overlap with the cells of the input raster based on the current computational region. Points in the resulting vector map are placed in cell centers of these cells. center stage, main character energy ๐Ÿ‘‘

๐Ÿ“ Number of cells and points ๐Ÿ“

You may specify the quantity of random locations to be generated either as a positive integer (e.g., 10), or as a percentage of the raster map's cells (e.g., 10%, or 3.05%). The number of cells considered for the percentage reflects whether or not the -n flag was given. Options are 0-100; fractions of percent may be stated as decimals (e.g., 66.67%, or 0.05%). math girlies rise up ๐Ÿงฎ

๐Ÿ’œ Values ๐Ÿ’œ

The cell values and corresponding category names (if present) associated with the random point locations in the input map are assigned to the newly generated cells in the raster map. If the -n is specified, then a unique entry is made for the value used where the input was NULL. This value is at least 1 less than the smallest value in the input raster and is given a medium gray color.

If a cover raster map is specified, values are taken from the cover raster map instead of the input raster map. If a cover raster map is specified and the cover map contains NULL (no data) values, these points are suppressed in the resulting vector or raster map. gone. deleted. not invited to the party ๐Ÿ™ˆ

๐ŸŒˆ Vector output ๐ŸŒˆ

The vector file created by r.random contains vector points that represent the center points of the randomly generated cells. A value attribute contains the cell value of the input raster (or the assigned value when -n is used). If a cover map is additionally specified, a second column covervalue is populated with raster values from the cover map.

If you set the -b flag, vector points are written without topology to minimize the required resources. This is suitable input to v.surf.rst and other vector modules. lowkey efficient ๐Ÿ’…


โญ NOTES โญ

To decide on the number of points r.random will create, use r.univar, g.region, or r.report. r.univar is the fastest way to obtain number of non-NULL cells and NULL cells in a raster map given the current computational region and raster mask:

r.univar map=inputmap

The text output contains total number of null and non-null cells (called cells in the machine-readable shell script style output), total null cells (null_cells), and number of non-null cells (n). Alternatively, you can use the following to examine the computational region and the raster map:

g.region -p
r.report map=inputmap units=c null="*" nsteps=1

To create random vector point locations within some, but not all, categories of a integer input raster map (aka CELL raster map), you must first create a reclassified raster map of the original raster map (e.g., using the GRASS module r.reclass) that contains only the desired categories, and then use the reclassed raster map as input to r.random. yes bestie, reclass first, then random. the pipeline is the pipeline ๐Ÿซถ


๐Ÿ”ฅ EXAMPLES ๐Ÿ”ฅ

๐ŸŒธ Random 2D vector elevation points ๐ŸŒธ

Random vector elevation points sampled from elevation map in the North Carolina sample dataset region, result stored in 2D vector map:

g.region raster=elevation -p
r.random elevation vector=elevrand n=100
v.db.select elevrand
v.univar elevrand col=value type=point

โœจ Random 3D vector elevation points โœจ

Random vector elevation points sampled from elevation map in the North Carolina sample dataset region with collocated values sampled from landuse map, result stored in 3D vector map:

g.region raster=elevation -p
r.random -z elevation cover=landclass96 vector=luserand3d n=100
# data output (value: elevation, covervalue: landuse class):
v.db.select luserand3d
cat|value|covervalue
1|111.229591|5
2|71.093758|1
3|122.51075|5
4|146.17395|4
...

๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

  • g.region for setting the computational region and examining the total number of cells,
  • r.reclass for working only with subset of values in the raster map,
  • v.random for generating vector points without any involvement of raster data,
  • r.random.cells for generating random cells with with spatial dependence (minimal distance),
  • r.surf.random as an option for generating random cell values,
  • v.surf.rst as an option for creating a surface from sampled points.

๐Ÿ’– AUTHORS ๐Ÿ’–

Dr. James Hinthorne, GIS Laboratory, Central Washington University

Modified for GRASS 5.0 by Eric G. Miller

Cover map support by Markus Neteler, 2007


๐ŸŒŸ SOURCE CODE ๐ŸŒŸ

Available at: r.random source code (history)

Accessed: Saturday Jan 17 05:40:56 2026

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index

okay that's the whole page bestie, and here's your lil sign-off: this manual is ยฉ 2003-2025 GRASS Development Team, straight out of the GRASS GIS 8.4.2 Reference Manual, and the source was accessed Saturday Jan 17 05:40:56 2026 ๐Ÿ’–โœจ slay, go make some random points ๐ŸŽ€

๐Ÿ“ฆ where this page comes from