Skip to content
代码片段 群组 项目
未验证 提交 1f241d28 编辑于 作者: Thomas Randolph's avatar Thomas Randolph
浏览文件

Add a seedable UUIDv4 generator

Most UUID generators assume that you want fully
random UUIDs. In most cases, this is true.

The `uuid` package allows
a consumer to pass in `random` values (an array
of 16 numbers 0-255), or a generator that outputs
16 random bytes.

This is our hook into being able to provide
"random" values. We just need a way to get
"random" values that are actually random in
most cases, but that we can control if we want
to.

Enter: the Mersenne Twister.
Mersenne Twisters can be seeded with a number
to start. They will derive all of their future twisted
states from that initial seed. So: we still get
"randomness," but we can also seed it to make
the output deterministic.

This `random.js` file outputs a single function
(for now) called `uuids` that will generate a
random UUIDv4 string or - if provided seeds -
will generate the correct resulting UUIDv4
given those seeds.

Consumers can request multiple values
to avoid having to constantly call the function
and/or constantly reconstruct the internal
Twister.
上级 d7ed9fff
No related branches found
No related tags found
无相关合并请求
加载中
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册