Expo universal module for random bytes
$ npm install 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.
For managed managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules package before continuing.
expo install expo-random
Run npx pod-install after installing the npm package.
No additional set up necessary.
import * as Random from 'expo-random';
getRandomBytesAsyncgetRandomBytesAsync(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);
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 />;
}
}
© 2010 - cnpmjs.org x YWFE | Home | YWFE