# react-native-randombytes

> randomBytes for react-native

Latest version **3.6.2** (published 2025-06-23) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install react-native-randombytes
pnpm add react-native-randombytes
yarn add react-native-randombytes
bun add react-native-randombytes
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.6.2 |
| Published | 2025-06-23 |
| First published | 2015-11-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 54.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mark Vayngrib |
| Maintainers | genevayngrib, pgmemk, tenaciousmv, spwilko |
| Keywords | react-component, react-native, randomBytes, rng, ios, android |

## Links

- npm: https://www.npmjs.com/package/react-native-randombytes
- Repository: https://github.com/mvayngrib/react-native-randombytes
- Homepage: https://github.com/mvayngrib/react-native-randombytes#readme
- Issues: https://github.com/mvayngrib/react-native-randombytes/issues
- npm.io page: https://npm.io/package/react-native-randombytes

## Dependencies (2)

- [sjcl](https://npm.io/package/sjcl.md) ^1.0.3
- [buffer](https://npm.io/package/buffer.md) ^4.9.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 3.6.2 (latest) — 2025-06-23
- 3.6.1 — 2021-04-22
- 3.6.0 — 2020-10-27
- 3.5.3 — 2019-05-13
- 3.5.2 — 2019-01-22
- 3.5.1 — 2018-09-16
- 3.5.0 — 2018-07-30
- 3.4.0 — 2018-07-03
- 3.3.0 — 2018-06-22
- 3.2.0 — 2018-05-22
- 3.1.0 — 2018-04-26
- 3.0.0 — 2017-08-29
- 2.3.0 — 2017-08-29
- 2.2.0 — 2016-11-10
- 2.1.0 — 2016-06-13
- … 4 more at https://npm.io/package/react-native-randombytes/versions

## README

# react-native-randombytes

## DEPRECATED

Use [react-native-get-random-values](https://www.npmjs.com/package/react-native-get-random-values) instead

## Usage

```js
import { randomBytes } from 'react-native-randombytes'

// synchronous API
// uses SJCL
const rand = randomBytes(4)

// asynchronous API
// uses iOS-side SecRandomCopyBytes
randomBytes(4, (err, bytes) => {
  // bytes is a Buffer object
  console.log(bytes.toString('hex'))
})
```

## Installation

1. Follow the steps in the next section
1. You have two options depending on your needs:
    1. if you're trying to get Node.js or browser crypto modules working in React Native, follow the installation workflow in [react-native-crypto](https://github.com/tradle/react-native-crypto).
    1. if you only need asynchronous random bytes generation, and don't care about getting back `Buffer` objects, you can do the following:

    ```js
    import { NativeModules } from 'react-native'
    const { RNRandomBytes } = NativeModules
    RNRandomBytes.randomBytes(32, (err, bytes) => {
      // bytes is a base64string
    })
    ```

### Automatic - Android / iOS (recommended)

```bash
react-native link
```

### Manual

If Automatic installation failed you, dry your tears and read on.

#### `iOS`

* Drag RNRandomBytes.xcodeproj from node_modules/react-native-randombytes into your XCode project.

* Click on the project in XCode, go to Build Phases, then Link Binary With Libraries and add `libRNRandomBytes.a`

Confused? See an example with screenshots [here](http://facebook.github.io/react-native/docs/linking-libraries-ios.html#content)


#### `Android`

* Update Gradle Settings

```gradle
// file: android/settings.gradle
...

include ':randombytes', ':app'
project(':randombytes').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-randombytes/android')
```

* Update Gradle Build

```gradle
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':randombytes')
}
```

* Register React Package

```java
...
import com.bitgo.randombytes.RandomBytesPackage // import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new RandomBytesPackage()) // register package here
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
        setContentView(mReactRootView);
    }
...

```

### `Windows`
 

```bash
react-native link react-native-randombytes
```

Depending on your project versions and the state of RN-Windows this may not always work. If it does not, a manual installation guide can be found here:

https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md

---
_Source: https://npm.io/package/react-native-randombytes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
