1 | # expo-random
|
2 |
|
3 | Provides 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 |
|
7 | For 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 |
|
9 | You 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
|
12 | import { polyfillWebCrypto } from 'expo-standard-web-crypto';
|
13 |
|
14 | polyfillWebCrypto();
|
15 | // crypto.getRandomValues is now globally defined
|
16 | ```
|
17 |
|
18 | Other 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 |
|
22 | For 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 | ```
|
27 | expo install expo-random
|
28 | ```
|
29 |
|
30 | ### Configure for iOS
|
31 |
|
32 | Run `npx pod-install` after installing the npm package.
|
33 |
|
34 | ### Configure for Android
|
35 |
|
36 | No additional set up necessary.
|