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 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);