14.0.1 • Published 7 months ago

expo-random v14.0.1

Weekly downloads
65,017
License
MIT
Repository
github
Last release
7 months ago

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

This package is pre-installed in managed Expo projects as of SDK 33. You may skip the rest of the installation guide if this applies to you.

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

npm install expo-random

Configure for iOS

Run pod install in the ios directory after installing the npm package.

Configure for Android

No additional set up necessary.

Docoumentation

// in managed apps:
import { Random } from 'expo';

// in bare apps:
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

NameTypeDescription
byteCountnumberA number within the range: 0...1024. Anything else will throw a TypeError

Returns

NameTypeDescription
randomBytesPromise<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 />;
  }
}
14.0.1

7 months ago

14.0.0

7 months ago

13.6.0

1 year ago

13.5.0

1 year ago

13.4.0

1 year ago

13.2.0

1 year ago

13.3.0

1 year ago

13.1.2

2 years ago

13.1.1

2 years ago

13.1.0

2 years ago

13.0.0

2 years ago

12.3.0

2 years ago

12.2.0

3 years ago

12.1.2

3 years ago

12.1.0

3 years ago

12.1.1

3 years ago

12.0.1

3 years ago

12.0.0

3 years ago

11.2.0

3 years ago

11.1.2

4 years ago

11.1.1

4 years ago

11.1.0

4 years ago

11.0.0

4 years ago

10.0.0

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.3.1

4 years ago

8.3.0

4 years ago

8.2.1

4 years ago

8.2.0

4 years ago

8.1.0

5 years ago

8.0.0

5 years ago

7.0.0

5 years ago

7.0.0-rc.0

5 years ago

6.0.0

5 years ago

6.0.0-rc.0

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

5.0.0-rc.0

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago