RandomInstance[expr]
finds a random instance of an expression such as a geometric scene or biomolecular sequence.
RandomInstance[expr,n]
finds n instances.
RandomInstance
RandomInstance[expr]
finds a random instance of an expression such as a geometric scene or biomolecular sequence.
RandomInstance[expr,n]
finds n instances.
Details and Options
- When expr is a GeometricScene, RandomInstance gives a GeometricScene or a list of GeometricScene objects.
- When expr is a BioSequence, RandomInstance gives a BioSequence or a list of BioSequence objects.
- RandomInstance makes assumptions by default. For example, it assumes points appearing in a GeometricScene are in general position and that regions appearing in a GeometricScene are nondegenerate.
- The following options can be given:
-
RandomSeeding Automatic how to seed randomness
Examples
open all close allBasic Examples (2)
Represent a symbolic geometric scene containing a triangle with points a, b, c and a 30° angle:
GeometricScene[{a, b, c}, {Triangle[{a, b, c}], PlanarAngle[{a, b, c}] == 30°}]RandomInstance finds a particular instance of the scene:
RandomInstance[%]Rules giving coordinates for the points have been filled in:
%//InputFormFind multiple instances of the scene:
RandomInstance[%1, 3]Find an arbitrary DNA sequence of length 12:
RandomInstance[BioSequence["DNA", 12]]Scope (1)
Options (1)
RandomSeeding (1)
By default, RandomInstance finds different solutions each time:
RandomInstance[GeometricScene[{a, b, c}, {Triangle[{a, b, c}]}], 2]Use RandomSeedingseed to use an explicit integer or string as a seed:
RandomInstance[GeometricScene[{a, b, c}, {Triangle[{a, b, c}]}], RandomSeeding -> 1]RandomInstance[GeometricScene[{a, b, c}, {Triangle[{a, b, c}]}], RandomSeeding -> 1]Applications (1)
Decompose a polygon into similar triangles:
RandomInstance[GeometricScene[
{a, b, c, d, e, o},
{
Polygon[{a, b, c, d, e}],
p1 == Style[Triangle[{a, b, o}], Red],
p2 == Style[Triangle[{b, o, c}], Blue],
p3 == Style[Triangle[{c, d, o}], Yellow],
p4 == Style[Triangle[{d, o, e}], Purple],
p5 == Style[Triangle[{e, o, a}], Orange],
GeometricAssertion[{p1, p2, p3, p4, p5}, "Similar"]
}
]]Properties & Relations (1)
Use RandomInstance to find random polygons:
RandomInstance[GeometricScene[{a, b, c, d, e}, {Polygon[{a, b, c, d, e}]}], 5]This can also be done with RandomPolygon:
Graphics /@ RandomPolygon[5, 5]Tech Notes
Related Guides
Text
Wolfram Research (2019), RandomInstance, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomInstance.html (updated 2020).
CMS
Wolfram Language. 2019. "RandomInstance." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/RandomInstance.html.
APA
Wolfram Language. (2019). RandomInstance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomInstance.html
BibTeX
@misc{reference.wolfram_2026_randominstance, author="Wolfram Research", title="{RandomInstance}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/RandomInstance.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_randominstance, organization={Wolfram Research}, title={RandomInstance}, year={2020}, url={https://reference.wolfram.com/language/ref/RandomInstance.html}, note=[Accessed: 13-June-2026]}