npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@liamegan1/fxhash-helpers

v1.0.0-beta.2

Published

A series of helper functions for FX Hash

Downloads

47

Readme

FX-Hash Helpers

Installation

Install the package using NPM:

npm install @liamegan1/fxhash-helpers

Quick-start

To get started with the library:

  • Import what you need as well as the FXInit function;
  • Initialise the library by passing the fxhash function to FXInit;
  • Use your helpers!
// import
import { FXInit, FXRandomBetween } from "@liamegan1/fxhash-helpers"

// Make sure you call FXInit before using any of the helpers!
FXInit( fxrand );

// Good to go!
const randomAngle = FXRandomBetween(-Math.PI, Math.PI);

Click here for a codesandbox demonstrating how this all works.

Details## Constants

Functions

FXInit

Initialises the library with a PRNG function. Most functions expect the PRNG to return 0-1 exclusive.

Kind: global constant

| Param | Description | | --- | --- | | prng | The PRNG function to use for subsequent calls |

FXRandomBetween

Returns a random float between two numbers.

FXRandomBetween(-10, 10); // -1.234576

Kind: global constant

| Param | Description | | --- | --- | | min | The minimum value | | max | The maximum value |

FXRandomIntBetween

Returns a random integer between two numbers - min, and max exclusive of max. If you want it to be inclusive of max, set the upper number to a floating point number like 10.99

FXRandomIntBetween(-10, 10); // 2

Kind: global constant

| Param | Description | | --- | --- | | min | The minimum value | | max | The maximum value |

FXRandomOption

Returns a random option from a provided list of options.

FXRandomOption(["I", "are", "weasel"]); // "weasel"

Kind: global constant

| Param | Description | | --- | --- | | options | An array of options to choose from |

FXRandomBool

Returns a random boolean given a weight (optional).

FXRandomBool(.2); // false

Kind: global constant

| Param | Default | Description | | --- | --- | --- | | weight | .5 | A weight to test the boolean against, if fxrand is less than this number, true is returned. Defaults to 0.5 |

FXRandVec2

Returns a 2-dimensional vector, expressed as an array, populated with random numbers

FXRandVec2(); // [.1234, .57351]

Kind: global constant

FXRandVec3

Returns a 3-dimensional vector, expressed as an array, populated with random numbers

FXRandVec3(); // [.1234, .57351, .01234]

Kind: global constant

FXRandVec4

Returns a 4-dimensional vector, expressed as an array, populated with random numbers

FXRandVec4(); // [.1234, .57351, .01234, .9634]

Kind: global constant

FXGetWeightedOption

Returns a weighted random option, given an array of options with weights.

let color = getWeightedOption([
  ["red", 10],
  ["green", 30],
  ["blue", 50],
]);

Curtesy Mark Knol, T: @mknol

Kind: global constant

| Param | Description | | --- | --- | | options | options in the format of [ [ string: optionName, int: optionNumber ] ] |

FXRandomGaussian

Returns a gaussian distributed random number. Bear in mind that calling FXRandomGaussian(5) will result in 5 calls to fxrand();

let gr = FXRandomGaussian(5);

Kind: global constant

| Param | Description | | --- | --- | | samples | The number of samples to use in the distribution. A higher sample number will result in a tighter bell-curve |

FXRandomReset

Resets the fxhash prng either to a new, random hash, or to a supplied hash. Use this if you want to reset the prng to its original state by calling:

FXRandomReset(fxhash);

or to a new, random hash simply by calling

FXRandomReset();

Note that resetting to a random hash uses the existing fxhash prng, which means that random hashes are also deterministic.

Kind: global constant

| Param | Type | Description | | --- | --- | --- | | newhash | string | [undefined] - A string value of the new hash to use. Mostly this parameter is used to reset the hash to the original. |

check()

Checks for the existance of the FXHash PRNG and throws an error if it doesn't exist.

Kind: global function