TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Generating Secure Random Numbers in TypeScript

2 点作者 ksbrooksjr超过 1 年前

1 comment

jepler超过 1 年前
There are better strategies for returning random numbers in a range, in terms of the fraction of values that will be rejected.<p>The code shown here recognizes the problem (the example of generating numbers from 0 to 25 inclusive) and finds a construct that makes things better (the modulo some-power-of-two step), but it&#x27;s possible to do better and have nearly no rejections.<p>Here&#x27;s a really good tutorial on some further steps that can be taken to reduce the quantity of numbers sampled, and make it faster to reject unusable numbers:<p><a href="https:&#x2F;&#x2F;sts10.github.io&#x2F;2020&#x2F;10&#x2F;10&#x2F;lemire-neaarly-divisionless-random.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;sts10.github.io&#x2F;2020&#x2F;10&#x2F;10&#x2F;lemire-neaarly-divisionle...</a><p>However, the initial &#x2F; best example assumes that 128 bit arithmetic types are available and reasonably efficient and I think that may not even be true in typescript(?).
评论 #38407937 未加载