A universal library for generating random bytes.
GitHub
npm
Deprecated: This module will no longer be available in SDK 49. Use expo-crypto instead.
expo-random
provides a native interface for creating strong random bytes. With Random
you can create values equivalent to Node.js core crypto.randomBytes
API. expo-random
also works with expo-standard-web-crypto
, which implements the W3C Crypto API for generating random bytes.
Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
-
npx expo install expo-random
If you are installing this in an existing React Native app (bare workflow), start by installing expo
in your project. Then, follow the additional instructions as mentioned by library's README under "Installation in bare React Native projects" section.
import * as Random from 'expo-random';
Random.getRandomBytes(byteCount)
Name | Type | Description |
---|---|---|
byteCount | number | A number within the range from |
Generates completely random bytes using native implementations. The byteCount
property
is a number
indicating the number of bytes to generate in the form of a Uint8Array
.
Falls back to Math.random
during development to prevent issues with React Native Debugger.
Uint8Array
An array of random bytes with the same length as the byteCount
.
Random.getRandomBytesAsync(byteCount)
Name | Type | Description |
---|---|---|
byteCount | number | A number within the range from |
Generates completely random bytes using native implementations. The byteCount
property
is a number
indicating the number of bytes to generate in the form of a Uint8Array
.
Promise<Uint8Array>
A promise that fulfills with an array of random bytes with the same length as the byteCount
.