How to use the react-native-sodium.randombytes_random function in react-native-sodium

To help you get started, we’ve selected a few react-native-sodium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyubo / react-native-sodium / Example / Example.js View on Github external
_testRandom3() {
    this.setState({randombytes_random:null})
    let freq = [];
    let p = []
    for (i = 0; i < 256; ++i) freq[i] = 0;
    for (i = 0; i < 5*256; ++i) p.push(Sodium.randombytes_random().then((v) => {
      ++freq[v & 0xff]
      ++freq[(v >>> 8) & 0xff]
      ++freq[(v >>> 16) & 0xff]
      ++freq[(v >>> 24) & 0xff]
    }))
    Promise.all(p).then(() => {
      var fail = false
      for (i = 0; i < 256 && !fail; ++i) if (!freq[i]) fail = true
      this.setState({randombytes_random:!fail})
    })
  }