Random

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.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

expo install expo-random

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

import * as Random from 'expo-random';

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.

  • byteCount (number) -- A number within the range: 0...1024. Anything else will throw a TypeError.

  • randomBytes (Uint8Array) -- An array of random bytes with the same length as the byteCount.

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.

  • byteCount (number) -- A number within the range: 0...1024. Anything else will throw a TypeError.

  • randomBytes (Promise<Uint8Array>) -- An array of random bytes with the same length as the byteCount.