What is react-native-get-random-values?
The react-native-get-random-values package is a polyfill for the Web Crypto API's getRandomValues method, which allows you to generate cryptographically strong random values in a React Native environment.
What are react-native-get-random-values's main functionalities?
Generate Random Values
This feature allows you to generate cryptographically strong random values. The code sample demonstrates how to use the getRandomValues method to fill a typed array with random values.
const { getRandomValues } = require('react-native-get-random-values');
const array = new Uint32Array(10);
getRandomValues(array);
console.log(array);
Other packages similar to react-native-get-random-values
react-native-crypto
The react-native-crypto package provides a full implementation of the Node.js crypto module for React Native. It includes functionalities for cryptographic operations such as hashing, encryption, and random value generation. Compared to react-native-get-random-values, it offers a broader range of cryptographic features.
react-native-securerandom
The react-native-securerandom package is designed to generate secure random numbers in a React Native environment. It is similar to react-native-get-random-values in that it focuses on generating cryptographically secure random values, but it does not polyfill the Web Crypto API.
getRandomValues
for React Native
A small implementation of getRandomValues
for React Native.
Installation
npm install --save react-native-get-random-values
cd ios && pod install && cd ..
Usage
This library works as a polyfill for the global crypto.getRandomValues
.
import 'react-native-get-random-values'
API
crypto.getRandomValues(typedArray)
The crypto.getRandomValues()
method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).
To guarantee enough performance, implementations are not using a truly random number generator, but they are using a pseudo-random number generator seeded with a value with enough entropy. The PRNG used differs from one implementation to the other but is suitable for cryptographic usages. Implementations are also required to use a seed with enough entropy, like a system-level entropy source.
typedArray
- Is an integer-based TypedArray, that is an Int8Array
, a Uint8Array
, an Int16Array
, a Uint16Array
, an Int32Array
, or a Uint32Array
. All elements in the array are going to be overridden with random numbers.
Returns the typed array that was passed in.