v.random(1grass)
β¨ v.random β the NAME β¨
okay bestie, welcome to the v.random page of the GRASS User's Manual π (yes it's v.random(1grass), we're fancy here).
Generates random 2D/3D vector points. that's it, that's the whole vibe π²β¨
π·οΈ KEYWORDS π·οΈ
vector, sampling, statistics, random, point pattern, stratified random sampling, level1
πΈ SYNOPSIS πΈ
v.random
v.random --help
v.random [-zab] output=name npoints=integer [restrict=name]
[layer=string] [cats=range] [where=sql_query] [zmin=float]
[zmax=float] [seed=integer] [column=name] [column_type=string]
[--overwrite] [--help] [--verbose] [--quiet] [--ui]
π Flags π
-zβ make the output 3D, live your three-dimensional truth π-aβ generatenpoints for each individual area (heads up: this one needs therestrictparameter)-bβ do not build topology. lowkey the move when you're handling a huge number of points π₯--overwriteβ allow output files to overwrite existing files (let it cook π³)--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output π€«--uiβ force launching GUI dialog
π¦ Parameters π¦
output=name[required] β name for output vector mapnpoints=integer[required] β number of points to be createdrestrict=nameβ name of input vector map. Restricts points to areas in the input vector.layer=stringβ layer number or name ('-1'for all layers). a single vector map can be connected to multiple database tables, and this number decides which table to use. when you're using direct OGR access, this is the layer name instead. Default:-1cats=rangeβ category values. Example:1,3,7-9,13where=sql_queryβ WHERE conditions of an SQL statement, no'where'keyword needed. Example:income < 1000 and population >= 10000zmin=floatβ minimum z height (needs the-zflag or a column name). Default:0.0zmax=floatβ maximum z height (needs the-zflag or a column name). Default:0.0seed=integerβ seed value for the random number generator. using the same seed ensures identical results, while a randomly generated seed produces different outcomes in each run. (reproducibility queen π)column=nameβ name of column for z values. writes z values to column.column_type=stringβ type of column for z values. Options:integer,double precision. Default:double precision
π DESCRIPTION π
v.random randomly generates vector points within the current region, using the selected random number generator. no cap, it just goes π²
it can also generate 3D vector points or write random values to the attribute table. the point height range / attribute value range is controlled by specifying the zmin and zmax options. and here's the tea: both z values are included in the range (zmin <= z <= zmax). inclusive, generous, iconic.
the generated random attribute value type is controlled by column_type. use integer column type for integers and double precision for floating point numbers. integer values get calculated by rounding a random floating point number. math slay β¨
if you want repeatable results, set a random seed with the seed option. same seed, same outcome, every single time. fr fr π«Ά
π Restriction to vector areas π
if a restrict vector map with areas is specified, the location of the random points gets restricted to the selected areas. by default, the requested number of points are distributed across all areas.
if the -a flag is given instead, the requested number of points is generated for each individual area. for example: if 20 points should be generated and the input map has 100 individual areas, you get 2000 points total. that escalated quickly π
attributes attached to the restrict vector map are also transferred if the layer parameter is defined > 0, see the example below.
π NOTES π
Importantly, attributes will only be transferred iflayer > 0(e.g.,layer=1). don't be out here wondering where your attributes went, bestie π₯²
π EXAMPLES π
all examples are based on the North Carolina sample dataset. (iykyk)
π Generating random points in 2D
generate 20 random points with binary attributes (only 0 or 1):
v.random output=binary_random npoints=20 zmin=0 zmax=1 column=βbinaryβ
v.db.select binary_random
cat|binary
1|0.63495
2|0.233421
3|0.489302
4|0.748264
5|0.505556
6|0.32975
[...]
v.univar -d binary_random
Calculating geometric distances between 20 primitives...
[...]
minimum: 148.515
maximum: 16572.8
[...]
π§ Generating random points in 2D with binary attributes
generate 20 random points with binary attributes (only 0 or 1):
v.random output=binary_random npoints=20 zmin=0 zmax=1 column=βbinaryβ column_type=integer
v.db.select binary_random
cat|binary
1|0
2|0
3|0
4|0
5|1
6|0
[...]
β Generating random points in 3D
generate 20 random 3D points using a specific random seed:
v.random seed=52 output=height_random npoints=40 zmin=110 zmax=170 -z
v.univar -d height_random
Calculating geometric distances between 40 primitives...
[...]
minimum: 334.889
maximum: 18351.9
range: 18017
sum: 5.38425e+06
mean: 7266.2
mean of absolute values: 7266.2
population standard deviation: 3563.95
[...]
skewness: 0.34703
random points with different X, Y, and Z coordinates π¦
πΈ Generating random points in selected areas
generate 3 random points only in selected areas ("RALEIGH" related ZIP code areas):
v.random restrict=zipcodes_wake output=zipcodes_local_random_n3 npoints=3 where="ZIPNAME = βRALEIGHβ" -a
# visualization
d.mon wx0
d.vect zipcodes_wake
d.vect zipcodes_wake fcolor=yellow where="ZIPNAME = βRALEIGHβ"
d.vect zipcodes_local_random_n3 color=red icon=basic/circle
fixed number of random points generated in selected areas β¨
π Generating random adjacent areas
to generate random adjacent areas, first the centroids are generated as points, then a triangulation is run (North Carolina sample dataset:
g.region vector=nc_state
v.random output=randpoints6k npoints=6000
v.voronoi input=randpoints6k output=randareas6k
v.info -t randareas6k
v.category randareas6k option=print
# plot vector areas
d.mon wx0
d.vect randareas6k -c
random adjacent areas from random points (here: used as centroids) π
to eventually obtain isolated areas, selected areas can be extracted with v.extract.
these vector areas can also be rasterized:
# rasterize areas
# note: rastermaps must result in at least 6k pixel in this example
g.region vector=nc_state res=500 -p -a
v.to.rast randareas6k out=randareas6k use=cat
r.colors randareas6k color=random
d.rast randareas6k
π¦ Random sampling from raster map
generate 20 random samples from a raster map:
g.region -p raster=elevation
v.random output=random_samples npoints=20
v.db.addtable map=random_samples columns=βcat INTEGER, sample DOUBLE PRECISIONβ
v.what.rast map=random_samples raster=elevation column=sample
v.db.select random_samples
cat|sample
1|103.9935
2|129.1266
3|96.01388
[...]
π Random sampling from vector map
generate 20 random points and sample attribute data from geology (vector) map:
g.region -p vector=geology
v.random output=random_samples npoints=20
v.db.addtable map=random_samples columns=βcat integer, geology varchar(100)β
v.what.vect map=random_samples column=geology query_map=geology query_layer=1 query_column=GEO_NAME
v.db.select random_samples
cat|geology
1|PzZm
2|
3|Zatm
[...]
π Stratified random sampling: Random sampling from vector map by attribute
generate 20 random points restricted to forested areas:
g.region -p raster=landclass96
r.to.vect -v input=landclass96 output=landclass96 type=area
v.random restrict=landclass96 output=random_samples npoints=20 where="label = βforestβ" layer=1
v.db.select map=random_samples
cat|landclass96_cat|landclass96_label
1|5|forest
2|5|forest
3|5|forest
...
random points only sampled in forested areas (stratified random sampling) π³
π₯ Stratified random sampling: Random sampling from vector map with spatial constraints
generating n points for each individual area: in this example two random points in each water body:
g.region -p raster=landclass96
r.to.vect -v input=landclass96 output=landclass96 type=area
v.random restrict=landclass96 output=random_samples npoints=2 where="label = βwaterβ" layer=1 -a
two random points sampled in each individual water body (stratified random sampling) π§
π«Ά SEE ALSO π«Ά
g.region, r.random, v.db.addtable, v.perturb, v.sample, v.univar, v.what.rast, v.what.vect
SQL support in GRASS
π AUTHOR π
James Darrell McCauley <darrell@mccauley-usa.com>, when he was at: Agricultural Engineering Purdue University
π SOURCE CODE π
Available at: v.random source code (history)
Latest change: Friday Aug 08 09:39:19 2025 in commit: ed72c71d8580e872cd6fd345c84a15c324764465
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
and that's a wrap bestie π¬π this was GRASS 8.5.0 β Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual, straight out of the v.random(1grass) page. go generate some points, you absolute icon πβ¨
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms