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/fake-lib-r-math-rng

v2.0.1

Published

將任意回傳 0~1 亂數 (Random Number) 的函式包裝為 lib-r-math.js 的 IRNG 介面 (Interface),方便把自訂的偽亂數發生器 (PRNG) 接入 R 統計函式

Downloads

267

Readme

@lazy-random/fake-lib-r-math-rng

將任意「回傳 0~1 亂數 (Random Number) 的函式」包裝為 lib-r-math.js 所使用的 IRNG 介面 (Interface),方便把自訂的偽亂數發生器 (PRNG) 接入 R 統計函式的實作。

特色 (Features)

  • 一行程式碼即可把 () => number 形式的亂數函式轉為 IRNG 物件
  • 同時提供 unif_rand 與 internal_unif_rand,符合 IRNG 的介面形狀 (Shape)
  • 支援批量產生:傳入 n > 1 時回傳長度為 n 的亂數陣列 (Array)
  • 無執行期 (Runtime) 相依,不需要安裝 lib-r-math.js 即可使用

安裝 (Installation)

yarn add @lazy-random/fake-lib-r-math-rng
yarn-tool add @lazy-random/fake-lib-r-math-rng
yt add @lazy-random/fake-lib-r-math-rng

使用方式 (Usage)

import fakeLibRMathRng from '@lazy-random/fake-lib-r-math-rng';

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

// 不傳參數:取得單一亂數
const value = rng.unif_rand();

// 傳入 n > 1:取得長度為 n 的亂數陣列
const values = rng.unif_rand(5);

// 兩個欄位指向同一個函式,可自由搭配 lib-r-math.js 相關實作的取用方式
rng.internal_unif_rand(3);

API 文件 (API Documentation)

fakeLibRMathRng(fn)

| 參數 (Parameter) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | fn | () => number | 底層亂數函式,每次呼叫回傳一個 0~1 的亂數 |

| 回傳值 (Returns) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | IRNG | IRNG | 包裝後的亂數發生器物件,含 unif_rand 與 internal_unif_rand |

unif_rand(n?)

| 參數 (Parameter) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | n | number \| undefined | 要產生的亂數個數;省略或不大於 1 時回傳單一亂數,大於 1 時回傳亂數陣列 |

IRNG 型別來自 lib-r-math.js,但因為是以型別 (Type) 方式引用,執行期並無此相依。

開發 (Development)

pnpm run build
pnpm run test:jest

變更日誌 (Changelog)

詳見 CHANGELOG.md。

相關資源 (Related Resources)