Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
438 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | if (global.crypto && global.crypto.getRandomValues) {
|
---|
| 4 | module.exports.randomBytes = function(length) {
|
---|
| 5 | var bytes = new Uint8Array(length);
|
---|
| 6 | global.crypto.getRandomValues(bytes);
|
---|
| 7 | return bytes;
|
---|
| 8 | };
|
---|
| 9 | } else {
|
---|
| 10 | module.exports.randomBytes = function(length) {
|
---|
| 11 | var bytes = new Array(length);
|
---|
| 12 | for (var i = 0; i < length; i++) {
|
---|
| 13 | bytes[i] = Math.floor(Math.random() * 256);
|
---|
| 14 | }
|
---|
| 15 | return bytes;
|
---|
| 16 | };
|
---|
| 17 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.