承接 tmarsteel/dprng 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tmarsteel/dprng

Composer 安装命令:

composer require tmarsteel/dprng

包简介

A deterministic pseudo-random number generator

README 文档

README

Implementation of a DPRNG algorithm aimed at being simple to implement in almost any general-purpose programming language. Its intended use are simple games; scenarios where a pseudo-random sequence has to be replayed deterministically with low memory and computational cost. The algorithm is not secure. DO NOT USE THIS FOR SECURITY RELATED TASKS.

A JavaScript implementation that generates equal sequences for the same salts/seeds can be found here

Please contribute with your own implementation in your favorite language! A description of the algorithm and test vectors can be found in algorithm.md. I`ll cross-link compliant forks :)

Installation & Usage

composer require tmarsteel/php-dprng:1.* or just download the single class file.

use tmarsteel\dprng\DPRNG;

// secure random numbers (seeded from mcrypt_create_iv() if available, rand() otherwise)
$rng = new DPRNG();

// deterministic random sequence
$seed = 0xA2F38C0;
$rng = new DPRNG($seed);

// generate random numbers
$random = $rng->next(); // random float from 0 inclusive to 1 exclusive (same range as Math.random())

$random = $rng->nextInt(14, 300); // random integer in the range 14 to 299

$bytes = $rng->nextBytes(30); // 30 random integers in the range 0 to 255

Entropy / Randomness inspection

ENT is a neat program to inspect the entropy and randomness of a sequence of bytes or bits. This table compares its output with values returned from rand(), mcrypt_create_iv() and this DPRNG. For explanations on the metrics see the ENT Website These numbers do only show that output of this DPRNG is sufficently random to be indistinguishable from random noise to HUMANS. Computers will be able to work out the initial salt given a RIDICULOUSLY SMALL SAMPLE!

RNG OS Entropy Arithmetic mean Chi-Square % Correlation coefficient Monte-Carlo PI error %
rand() Windows 10 7.998118 127.6669 99.99 -0.006520 0.55
DPRNG seeded by mcrypt_create_iv() Windows 10 7.992490 127.7548 29.17 0.005192 0.02
mcrypt_create_iv() Windows 10 7.993520 127.6631 86.44 0.010960 0.37
rand() Ubuntu 15.10 7.992890 127.6763 56.82 -0.004945 1.15
DPRNG seeded by mcrypt_create_iv() (a) Ubuntu 15.10 7.993482 127.8451 84.77 -0.000205 2.43
mcrypt_create_iv()(b) Ubuntu 15.10 7.993261 127.4429 73.70 0.000831 0.4

You can run these tests yourself with the ent executable and the entTestfile.php script.
(a) source = MCRYPT_DEV_RANDOM
(b) source = MCRYPT_DEV_URANDOM

Methods

Here is a full list of the methods supported by tmarsteel\dprng\DPRNG objects and their signatures + contracts:

float next()
Returns an uniformly distributed float value in the range [0, 1) (0 inclusive to 1 exclusive).

float nextFloat(float $from, float $to)
Returns an uniformly distributed float value in the range [$from, $to) ($from inclusive to $to exclusive).

int nextInt(int $from, int $to)
Returns an uniformly distributed integer in the range [$from, $to] ($from inclusive to $to inclusive).

array nextBytes(int $n)
Returns an array of length $n. Each entry is a uniformly distributed integer between 0 and 255.

tmarsteel/dprng 适用场景与选型建议

tmarsteel/dprng 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「random」 「deterministic」 「RNG」 「dprng」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tmarsteel/dprng 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tmarsteel/dprng 我们能提供哪些服务?
定制开发 / 二次开发

基于 tmarsteel/dprng 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-12