expo-random

Expo universal module for random bytes

This package is now deprecated in favor of expo-crypto, which provides the same functionality. To migrate, replace all imports from expo-random with imports from expo-crypto.
Last updated 7 years ago by tsapeta .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install expo-random 
SYNC missed versions from official npm registry.

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.

Installation in managed Expo projects

For managed managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.

Installation in bare React Native projects

For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules package before continuing.

Add the package to your npm dependencies

expo install expo-random

Configure for iOS

Run npx pod-install after installing the npm package.

Configure for Android

No additional set up necessary.

Documentation

import * as Random from 'expo-random';

Methods

getRandomBytesAsync

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.

Parameters

Name Type Description
byteCount number A number within the range: 0...1024. Anything else will throw a TypeError

Returns

Name Type Description
randomBytes Promise<Uint8Array> An array of random bytes with the same length as the byteCount

Example

const randomBytes = await Random.getRandomBytesAsync(3);

Usage

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 />;
  }
}

Current Tags

  • 0.0.1-canary-20240418-8d74597                                ...           canary (3 years ago)
  • 14.0.1                                ...           latest (3 years ago)
  • 13.6.0                                ...           sdk-50 (3 years ago)
  • 14.0.1                                ...           sdk-51 (3 years ago)

68 Versions


© 2010 - cnpmjs.org x YWFE | Home | YWFE