Документация Engee

Random

Страница в процессе перевода.

rand([rng], G, crs=Cartesian3D)

Generate a random geometry of type G with CRS crs, optionally passing a random number generator rng.

Examples

rand(Point)
rand(Triangle)
rand(Point, crs=Cartesian2D)
rand(Triangle, crs=LatLon)
rand([rng], G, n, crs=Cartesian3D)

Generate a vector of n random geometries of type G with CRS crs, optionally passing a random number generator rng.

Examples

rand(Point, 10)
rand(Triangle, 10)
rand(Point, 10, crs=Cartesian2D)
rand(Triangle, 10, crs=LatLon)

Random geometries can be generated using the rand function:

rand(Point)
Point with Cartesian{NoDatum} coordinates
├─ x: 0.5752199435838631 m
├─ y: 0.3519192144770379 m
└─ z: 0.9096284027676678 m

By default, the rand function uses the Cartesian3D CRS (Coordinate Reference System). It’s possible to change the CRS using the crs keyword argument:

rand(Point, crs=Cartesian2D)
Point with Cartesian{NoDatum} coordinates
├─ x: 0.19273650203599502 m
└─ y: 0.4371137347695484 m

A vector of geometries can be generated by passing the number of elements as the second argument:

rand(Segment, 5, crs=LatLon)
5-element Vector{Segment{🌐, GeodeticLatLon{WGS84Latest, Quantity{Float64, NoDims, Unitful.FreeUnits{(°,), NoDims, nothing}}}}}:
 Segment((lat: -75.9285°, lon: 22.7984°), (lat: 5.60715°, lon: -142.115°))
 Segment((lat: -15.3766°, lon: 167.285°), (lat: -40.552°, lon: 17.7737°))
 Segment((lat: -23.2019°, lon: -66.3157°), (lat: -43.3256°, lon: -33.4628°))
 Segment((lat: -27.0493°, lon: 87.0277°), (lat: -60.3802°, lon: 41.1961°))
 Segment((lat: -4.51623°, lon: -79.663°), (lat: -66.3512°, lon: -70.4392°))

For reproducibility purposes, a random number generator can be passed as the first argument in both methods:

rng = MersenneTwister(123)
rand(rng, Triangle)
Triangle
├─ Point(x: 0.7684476751965699 m, y: 0.940515000715187 m, z: 0.6739586945680673 m)
├─ Point(x: 0.3954531123351086 m, y: 0.3132439558075186 m, z: 0.6625548164736534 m)
└─ Point(x: 0.5860221243068029 m, y: 0.05213316316865657 m, z: 0.26863956854495097 m)
rand(rng, Triangle, 5)
5-element Vector{Triangle{𝔼{3}, Cartesian3D{NoDatum, Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}:
 Triangle((x: 0.108871 m, y: 0.163666 m, z: 0.473017 m), (x: 0.865412 m, y: 0.617492 m, z: 0.285698 m), (x: 0.463847 m, y: 0.275819 m, z: 0.446568 m))
 Triangle((x: 0.582318 m, y: 0.255981 m, z: 0.70586 m), (x: 0.291978 m, y: 0.281066 m, z: 0.792931 m), (x: 0.20923 m, y: 0.918165 m, z: 0.614255 m))
 Triangle((x: 0.802665 m, y: 0.555668 m, z: 0.940782 m), (x: 0.48 m, y: 0.790201 m, z: 0.356221 m), (x: 0.900925 m, y: 0.529253 m, z: 0.031831 m))
 Triangle((x: 0.900681 m, y: 0.940299 m, z: 0.621379 m), (x: 0.348173 m, y: 0.570613 m, z: 0.203997 m), (x: 0.37498 m, y: 0.759755 m, z: 0.19178 m))
 Triangle((x: 0.234544 m, y: 0.0976698 m, z: 0.627093 m), (x: 0.946697 m, y: 0.546904 m, z: 0.122594 m), (x: 0.110365 m, y: 0.51468 m, z: 0.628172 m))