node-random-number-csprng | cryptographically secure generator for random | Generator Utils library
kandi X-RAY | node-random-number-csprng Summary
kandi X-RAY | node-random-number-csprng Summary
A cryptographically secure generator for random numbers in a range.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculates the inverse of the given range .
node-random-number-csprng Key Features
node-random-number-csprng Examples and Code Snippets
Community Discussions
Trending Discussions on node-random-number-csprng
QUESTION
I am trying to shuffle an array using a cryptographically secure source of entropy.
I found a similar question, regarding shuffling arrays here How to randomize (shuffle) a JavaScript array?. However almost all solutions make use of Math.random
, which is not secure.
Unfortunately I do not have the reputation to comment/post on that question.
Here is the solution I came up with, which uses Durstenfeld shuffling paired with a CSPRNG for generating random integers in a given range (provided by random-number-csprng lib).
...ANSWER
Answered 2018-Apr-27 at 17:55After reviewing extensively, I have concluded that the solution is correct, being a verbatim implementation of the Durstenfeld shuffle.
However, the Durstenfeld / Fisher-Yates shuffle is only as random as it's RNG source. My solution depends on the random-number-csprng CSPRNG lib, which uses crypto.randomBytesAsync
, and is therefore cryptographically secure for most all purposes (see How random is crypto#randomBytes?).
UPDATE: I have published a functionally equivalent yet more efficient version of this solution here crypto-secure-shuffle, also available as an npm package. Here is the relevant implementation:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install node-random-number-csprng
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page