Untitled

šŸ“°Getting Started | ā­**Updates |** šŸ“ Guides | šŸ”¢ API | ā“FAQ

Guides Overview

Random

The Random API provides several utilities for random value generation that aren't covered by the built-inĀ JS Math API. Use theĀ random-previewĀ import to access extended random value utilities.

Note that these values are not intended to be used in cryptography. All documentation for this Random API uses proper interval notation. For example,Ā [0, 1)Ā means the value may equal 0 but excludes 1.

Floats

// Imports the Random API
const random = require('random-preview');

// Generates a random float in (0, 1)
var val = random.value();

// Generates a random float in [min, max]
var val = random.range(0, 10);

Integers

// Imports the Random API
const random = require('random-preview');

// Generates a random int in [min, max]
var val = random.rangeInt(0, 10);

/*
Generates a random index for an array
This will return an int value in [0, len)
*/
var val = random.index(myArray.length);

3D

// Imports the Random API
const random = require('random-preview');

/*
Generates a random Quat. This method will produce a distribution
that is uniform across the full rotation of each axis, rather than
component wise, which produces an unequally weighted distribution.
*/
var a = random.quat();

// Generates a random distribution of two dimensional vectors.
var vecs = random.distribution(radius, count);

Next: Scene Editing

Sidebar Table of Contents


Untitled

Copyright Ā© 2021 Enklu, Inc.