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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lazy-random/generators-function

v2.0.1

Published

把任意回傳 0~1 亂數 (Random Number) 的函式包裝為 RNG 類別,讓自訂函式也能使用統一的亂數產生器 (Random Number Generator) API

Readme

@lazy-random/generators-function

把任意「回傳 0~1 亂數 (Random Number) 的函式」包裝為 @lazy-random/rng-abstract 的 RNG 類別,讓自訂函式也能使用統一的亂數產生器 (Random Number Generator) API。

特色 (Features)

  • 一行程式碼即可把 (...argv) => number 形式的函式轉為 RNGFunction 實例 (Instance)
  • 繼承 RNG 抽象類別,取得 next()、clone()、seedable 等共用 API
  • 建構期以斷言 (Assertion) 檢查傳入值,非函式時提早失敗 (Fail Fast)
  • 透過 @lazy-random/clone-class 支援帶著同一個底層函式建立新實例

安裝 (Installation)

yarn add @lazy-random/generators-function
yarn-tool add @lazy-random/generators-function
yt add @lazy-random/generators-function

使用方式 (Usage)

import RNGFunction from '@lazy-random/generators-function';

// 以任意回傳 0~1 的函式作為底層亂數來源 (Entropy Source)
const rng = new RNGFunction(() => Math.random());

// 取得一個 0~1 的亂數
const value = rng.next();

// 產生器識別名稱
console.log(rng.name); // 'function'

// 以同一個底層函式複製出新的實例
const cloned = rng.clone(() => Math.random());
import { RNGFunction, IRNGFunctionSeed } from '@lazy-random/generators-function';

// 具名匯出與型別 (Type) 匯出
const fn: IRNGFunctionSeed = () => Math.random();
const rng: RNGFunction<typeof fn> = new RNGFunction(fn);

API 文件 (API Documentation)

new RNGFunction(seed, opts?, ...argv)

| 參數 (Parameter) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | seed | IRNGFunctionSeed((...argv) => number) | 底層亂數函式;非函式且非 null/undefined 時會失敗 | | opts | any | 保留的選項參數 (Options),目前未使用 | | ...argv | any[] | 保留的其餘參數,透傳給 _init 與 seed |

方法 (Methods)

| 方法 (Method) | 回傳值 (Returns) | 說明 (Description) | | --- | --- | --- | | next() | number | 呼叫底層函式並回傳一個亂數 | | seed(seed, opts?, ...argv) | void | 當 seed 為函式時取代底層亂數函式 | | clone(seed, opts?, ...argv) | RNGFunction<S> | 以同一個類別與底層狀態建立新實例 |

屬性 (Properties)

| 屬性 (Property) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | name | string | 固定回傳 'function' | | seedable | boolean | 是否支援以種子 (Seed) 重建序列,依底層函式而定 |

型別 (Types)

IRNGFunctionSeed

type IRNGFunctionSeed = (...argv) => number

用作底層亂數函式的型別 (Type) 別名 (Alias)。

開發 (Development)

pnpm run build
pnpm run test:jest

變更日誌 (Changelog)

詳見 CHANGELOG.md。

相關資源 (Related Resources)