
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
prng-well1024a
Advanced tools
This is a Javascript implementation of the WELL-1024a pseudorandom number generation algorithm.
Javascript's built-in Math.random()
function is
implementation-dependent
and therefore of limited usefulness if your program depends on random
numbers, as you risk running into crappy implementations. Even the V8
engine (used by Node.js) only provides 32-bit entropy, and is based on
the platform-dependent C++ rand()
function.
This module is very bare-bones. I have also written a randomness library called
randy that provides useful functions like
RandInt(min, max)
, shuffle(array)
etc., based on this module.
var rng = well1024a();
var number = rng.getUInt32();
var coin = ['heads', 'tails'][number % 2];
// coin == 'heads'
## Download
npm install prng-well1024a
### In the Browser
Download and include as a <script>
. The module will be available as
the global object randy
.
Development: well1024a.js - 2Kb Uncompressed
Production: well1024a.min.js - < 1Kb Minified
Example
<script src="well1024a.min.js"></script>
I am <span id="age"></span> years old!
<script>
var n = document.getElementById("age");
var myAge = well1024a.getUInt32();
n.innerText = myAge.toString();
</script>
Returns a new well1024a instance, which is an object with 3 functions:
The instance will use Math.random()
to fill out the initial seed state.
Arguments
/dev/urandom
etc.Example
var w = well1024a([
Date.now(),
os.freemem(),
process.pid
]);
## getUInt32()
Returns a random positive integer less than 2^32.
Example
var w = well1024a();
console.log('For Christmas this year, I want ' + w.getUInt32().toString() + ' ponies!');
## getState()
Returns an array of 32-bit unsigned integers, of length 32. This represents the current state of the random number generator.
This array can be used as a parameter to setState
.
Sets the random number generator to a specific state, allowing for replay of random values.
General use case is to give it a value previously received by calling getState()
.
Arguments
Example
This will flip a pair of coins, reset the generator state, and flip the coins again with the exact same output.
var w = well1024a();
var coins = ['heads', 'tails'];
console.log("Flippin' the coins:");
var state = w.getState();
var d1 = coins[w.getUInt32() % 2];
var d2 = coins[w.getUInt32() % 2];
console.log(d1 + " and " + d2);
console.log("Instant replay:");
w.setState(state);
d1 = coins[w.getUInt32() % 2];
d2 = coins[w.getUInt32() % 2];
console.log(d1 + " and " + d2);
No functions rely on this
, so it's safe to e.g. assign
randy.good.randInt
to a variable or pass it around as a
parameter.
FAQs
Random number generator based on WELL-1024a algorithm.
The npm package prng-well1024a receives a total of 3,747 weekly downloads. As such, prng-well1024a popularity was classified as popular.
We found that prng-well1024a demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.