Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
The xorshift npm package is a JavaScript implementation of the xorshift family of pseudorandom number generators (PRNGs). It is designed to provide fast and high-quality random number generation suitable for various applications such as simulations, games, and procedural content generation.
Basic Random Number Generation
This feature allows you to generate a basic random number using the xorshift algorithm. The `random` method returns a floating-point number between 0 and 1.
const xorshift = require('xorshift');
const rng = xorshift.create();
console.log(rng.random());
Seeded Random Number Generation
This feature allows you to initialize the random number generator with a specific seed. This is useful for reproducible results in simulations or tests.
const xorshift = require('xorshift');
const seed = [1, 2, 3, 4];
const rng = xorshift.create(seed);
console.log(rng.random());
Random Integer Generation
This feature allows you to generate a random integer. The `randomint` method returns a 32-bit integer.
const xorshift = require('xorshift');
const rng = xorshift.create();
console.log(rng.randomint());
Random Number Generation in a Range
This feature allows you to generate a random number within a specified range. The `randomInRange` function demonstrates how to use the `random` method to achieve this.
const xorshift = require('xorshift');
const rng = xorshift.create();
function randomInRange(min, max) {
return min + Math.floor(rng.random() * (max - min + 1));
}
console.log(randomInRange(1, 100));
The seedrandom package provides a seeded random number generator that can be used to create reproducible random sequences. It supports multiple algorithms including Alea, XOR128, and Tychei. Compared to xorshift, seedrandom offers more flexibility in terms of algorithms and seeding options.
The random-js package is a versatile random number generator library that supports multiple PRNG algorithms including Mersenne Twister and native Math.random. It provides a rich set of features for generating random numbers, integers, and booleans, as well as shuffling arrays. Compared to xorshift, random-js offers a broader range of algorithms and utilities.
The chance package is a comprehensive library for generating random data in JavaScript. It includes functions for generating random numbers, strings, dates, and even entire objects. While xorshift focuses on efficient random number generation, chance provides a wide array of random data generation utilities.
#xorshift
Random number generator using xorshift
NOT YET PUBLISHED # npm install xorshift
var xorshift = require('xorshift')
var bview = require('binary-view');
for (var i = 0; i < 10; i++) {
console.log(bview(xorshift()));
}
This repo also contains an reference implementation of the 128bit xorshift. First you should compile the code.
gcc -O2 reference.c -o reference
Next you should execute the binary
./reference <numbers>
<numbers>
can be any number greater than zero, and it will be the amount
if random numbers in the stdout. The default value is 10
.
##License
The software is license under "MIT"
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Random number generator using xorshift128+
The npm package xorshift receives a total of 400,878 weekly downloads. As such, xorshift popularity was classified as popular.
We found that xorshift 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
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.