Provides a native interface for creating strong random bytes. With Random you can create values equivalent to Node.js core crypto.randomBytes API.

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

For managed apps, you'll need to run expo install expo-random. To use it in a bare React Native app, follow its installation instructions.

import React from 'react';
import { View } from 'react-native';
import * as Random from 'expo-random';

export default class DemoView extends React.Component {
  async componentDidMount() {
    const randomBytes = await Random.getRandomBytesAsync(16);

    /* Some crypto operation... */
  render() {
    return <View />;

import * as Random from 'expo-random';

getRandomBytesAsync(byteCount: number): Promise<Uint8Array>
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.
byteCountnumberA number within the range: 0...1024. Anything else will throw a TypeError
randomBytesPromise<Uint8Array>An array of random bytes with the same length as the byteCount
const randomBytes = await Random.getRandomBytesAsync(3);