UNPKG

1.52 kBMarkdownView Raw
1# expo-random
2
3Provides a native interface for creating strong random bytes. With `Random` you can generate random values to address use cases that other APIs like the web's `crypto.getRandomValues` and Node's `crypto.randomBytes` might address.
4
5# Installation in managed Expo projects
6
7For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/) Expo projects, please follow the installation instructions in the [API documentation for the latest stable release](https://docs.expo.io/versions/latest/sdk/random/).
8
9You can add a polyfill for the web's `crypto.getRandomValues` by installing [expo-standard-web-crypto](https://github.com/expo/expo/tree/master/packages/expo-standard-web-crypto) and importing it in SDK 39 and higher:
10
11```js
12import { polyfillWebCrypto } from 'expo-standard-web-crypto';
13
14polyfillWebCrypto();
15// crypto.getRandomValues is now globally defined
16```
17
18Other libraries like [react-native-get-random-values](https://github.com/LinusU/react-native-get-random-values) may work too.
19
20# Installation in bare React Native projects
21
22For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
23
24### Add the package to your npm dependencies
25
26```
27expo install expo-random
28```
29
30### Configure for iOS
31
32Run `npx pod-install` after installing the npm package.
33
34### Configure for Android
35
36No additional set up necessary.