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-crypto

v2.0.1

Published

以加密安全亂數來源 (Cryptographically Secure RNG) 實作的亂數產生器 (Random Number Generator),適合需要較高不可預測性 (Entropy) 的场合

Readme

@lazy-random/generators-crypto

以加密安全亂數來源 (Cryptographically Secure RNG) 實作的亂數產生器 (Random Number Generator),繼承 @lazy-random/rng-abstract 的 RNG 抽象類別,適合需要較高不可預測性 (Entropy) 的场合。

特色 (Features)

  • 底層透過 @lazy-random/cross-crypto 取得跨平台的加密亂數來源 (Crypto-like Source)
  • 內建可注入的 ICryptoLike 介面,測試時可替換成自訂亂數來源
  • 提供 next() 取得 0~1 浮點亂數 (Float Random Number)
  • 支援自訂緩衝區大小 (Buffer Size),並夾限 (Clamp) 在 UINT32_BYTES ~ 255 位元組 (Bytes)

安裝 (Installation)

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

使用方式 (Usage)

import RNGCrypto from '@lazy-random/generators-crypto';

// 使用預設的 cross-crypto 亂數來源
const rng = new RNGCrypto();

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

console.log(value);
import { RNGCrypto } from '@lazy-random/generators-crypto';

// 注入自訂的 crypto-like 物件(需具備 randomBytes(size) 方法)
const rng = new RNGCrypto({
	randomBytes(size: number)
	{
		return Buffer.alloc(size, 7);
	},
});

rng.next();

API 文件 (API Documentation)

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

| 參數 (Parameter) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | seed | ICryptoLike \| any | 可傳入自訂的 crypto-like 物件;省略時使用 crossCrypto() | | opts | any | 保留的選項參數 (Options),目前未使用 | | ...argv | any[] | 保留的其餘參數,透傳給 _init |

方法 (Methods)

| 方法 (Method) | 回傳值 (Returns) | 說明 (Description) | | --- | --- | --- | | next() | number | 產生並回傳一個 0~1 的浮點亂數 | | seed(seed?, opts?, ...argv) | void | 保留 API;加密亂數來源不支援固定亂數種子 (Seed),目前為空實作 |

屬性 (Properties)

| 屬性 (Property) | 型別 (Type) | 說明 (Description) | | --- | --- | --- | | name | string | 固定回傳 'crypto' |

設定 (Configuration)

| 欄位 (Field) | 預設值 (Default) | 說明 (Description) | | --- | --- | --- | | _seed_size | UINT32_BYTES(夾限至 255) | 每次取得亂數時要求的緩衝區位元組數 | | _seed_size_min | UINT32_BYTES(夾限至 255) | 緩衝區位元組數的下限,低於此值時會被抬高 | | _randIndex | arrayRandIndexByLength | 當緩衝區大於下限時,用來決定截取起點的索引函式 (Index Function) |

開發 (Development)

pnpm run build
pnpm run test:jest

變更日誌 (Changelog)

詳見 CHANGELOG.md。

相關資源 (Related Resources)