š°Getting Started | ā**Updates |** š Guides | š¢ API | āFAQ
Web Editor Basics
HoloLens
Mobile
Meta Quest
Chapter Series Documentation
Assets
Scripting
Enklu Embedded
API Reference
Release Notes
FAQ
Contact
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.
// 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);
// 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);
// 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
Copyright Ā© 2021 Enklu, Inc.