IMoneyHub.com
Menu
  • ParseAbout.com News
Menu

Tiny Unopinionated Random Number Generator For JavaScript – Aimless.js

Posted on May 26, 2023 by admin

random-number-generator-aimless

Aimless.js is a lightweight, unopinionated, zero-dependency random number generator written in JavaScript.

It provides several utilities for generating random numbers, picking random elements from arrays, getting random integers within a range, and more. You can also integrate Aimless.js with your favorite PRNGs (pseudo-random number generators) to provide an additional layer of randomness to your applications.

How to use it:

1. Install the Aimless.js and import utilities of your choice as follows:

# NPM
$ npm i aimless.js
import { 
  bool, // or boolWithEngine
  char, // or charWithEngine
  customDist, // or customDistWithEngine
  exponentialDist, // or exponentialDistWithEngine
  floatRange, // or floatRangeWithEngine
  intRange, // or intRangeWithEngine
  intSequence, // or intSequenceWithEngine
  normalDist, // or normalDistWithEngine
  normalFloat, // or normalFloatWithEngine
  oneOf, // or oneOfWithEngine
  seedFunc
  sequence, // or sequenceWithEngine
  sign, // or signWithEngine
  uniqFuncIntRange
  uniqFuncSequence
  uuid, // or uuidWithEngine 
  weighted, // or weightWithEngine
} from 'aimless.js'

2. API methods.

// returns true of false 
const engine = () => 0
bool(engine) 

// returns a random character from the provided string.
const randomChar = char('random characters')

// returns a random number following a custom distribution
const randomOfCustomDist = customDist(
  (randomNumber) => randomNumber / 5
)

// Returns a random number following an exponential distribution with the provided lambda.
const samples = []
const lambda = 0.5
for (let i = 0; i < 100000; i++) {
  const randomValue = exponentialDist(lambda)
  samples.push(randomValue)
}

// returns a random float between min and max.
const randomFloat = floatRange(0.1, 0.5)

// returns a random integer between min and max.
const randomInteger = intRange(1, 100)

// returns an array with all integers between min and max in random order.
const intSeq = intSequence(-5, 5)

// returns a random number following a normal distribution with mean and standard deviation stdDev
const samples = []
for (let i = 0; i < 100000; i++) {
  const randomValue = normalDist(0, 1)
  samples.push(randomValue)
}

// returns a random float between -1 and 1.
normalFloat(engine)

// returns a random item from the array provided.
const randomItem = oneOf([1,2,3])
const randomObj = oneOf([{a:1}, {b:2}, {c:3}])

// returns a seeded random number generator. Seeded RNGs produce random numbers, but are predictable if you use the same seed. 
// note: the Park-Miller PRNG is used to provide the seeded function, therefore, an engine is not accepted.
seedFunc(seed)
const seededFunction = seedFunc(1)
seededFunction() // 0.000007825903601782307
seededFunction() // 0.13153778773875702
seededFunction() // 0.7556053220812281
const newSeeded = seedFunc(1)
newSeeded() // 0.000007825903601782307
newSeeded() // 0.13153778773875702
newSeeded() // 0.7556053220812281
sequence(array, engine)

// returns a new array with the same items contained in array but in random order.
const randomSeq = sequence([1,2,3])

// returns either -1 or 1.
sign(engine)

// returns a unique random number between min and max
const uniqueRNG = uniqFuncIntRange(1, 3)
uniqueRNG() // 2
uniqueRNG() // 3
uniqueRNG() // 1
uniqueRNG() // null

// returns a unique random number from the provided array
const uniqueRNG = uniqFuncSequence([10, 20, 30])
uniqueRNG() // 20
uniqueRNG() // 30
uniqueRNG() // 10
uniqueRNG() // null

// returns a valid RFC4122 version4 ID hex string
const id = uuid()
console.log(id)

// returns one of the numbers provided
const weightedDiceRoll = weighted(
  [1,2,3,4,5,6],
  [1,1,1,1,1,10]
)

The post Tiny Unopinionated Random Number Generator For JavaScript – Aimless.js appeared first on CSS Script.

* This article was originally published here

1 thought on “Tiny Unopinionated Random Number Generator For JavaScript – Aimless.js”

  1. Michaeljindy says:
    May 26, 2023 at 12:12 pm

    http://fastdeliverypill.com/# good online mexican pharmacy

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Stackable Mockup: massive library of realistic high-def mock-ups #ad
  • The many ways to select the n-th character from a string.
  • Photoshopped Ben Affleck pic goes viral—’Long day at work in 2035′
  • 🌱 Biennial Reappraisals Arriving Soon + Ken Burns Headed To Town – Patch.com
  • Air quality live updates: New York City has the worst air in the world as smoke from Canadian wildfires rolls in – NBC News

Recent Comments

  1. Lelanddek on Pyra-Grid: Gaming
  2. fildenafilcom on Megan Thee Stallion Releases Her Blacked-Out “Plan B” Video
  3. CharlesZef on “Outer Banks” Fans, Get Ready – Season 3 Finally Premieres Next Month
  4. Lelanddek on Absent Letter Musical Instruments
  5. BennyEmito on Porteus project/forums/website

Archives

  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022

Categories

  • Affiliate Marketing
  • Bing
  • Buzzfeed
  • Centos
  • Clickbank
  • Copywriting
  • CSS
  • Ebay
  • Google
  • HTML
  • Internet Marketing
  • Javascript
  • Linux
  • Make Money Online
  • News
  • PHP
  • PopSugar
  • Technology
  • Trivia
  • Uncategorized
  • Video
  • Viral
  • Web Design

Menu

  • 15,000 Articles $3
  • 300,000 PLR Articles $17
  • PLR Pack 9 Million Articles with Resale Rights $17
  • Free Design Application – Design Bundle
  • Free Traffic Application – Trafficize Plus Reseller
  • Internet Applications and Products
  • Business Leads Software. Access millions of leads. You can sell the leads.
  • Free Products
  • Thousands of Giveaways
  • Our Online Store
  • Use Our 88 Online Website Tools

©2023 IMoneyHub.com | Design: Newspaperly WordPress Theme