How to use the react-native-sodium.randombytes_uniform 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
_testRandom1() {
    this.setState({randombytes_uniform:null})
    let freq = [];
    let p = []
    for (i = 0; i < 256; ++i) freq[i] = 0;
    for (i = 0; i < 20*256; ++i) p.push(Sodium.randombytes_uniform(256).then((v) => ++freq[v]))
    Promise.all(p).then(() => {
      var fail = false
      for (i = 0; i < 256 && !fail; ++i) if (!freq[i]) fail = true
      this.setState({randombytes_uniform:!fail})
    })
  }