# std: introduce a thread-local CSPRNG for general use · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/013efaf13987acfa6b41d40f07900c1ea77f5bda)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 013efaf13987acfa6b41d40f07900c1ea77f5bda

Requested commit: 013efaf13987acfa6b41d40f07900c1ea77f5bda

Commit: 013efaf13987acfa6b41d40f07900c1ea77f5bda

Tree: 14325d114eb66312b3545f3a897142400dfb7c16

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
std: introduce a thread-local CSPRNG for general use

std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704

```

## Parents

- [ce65533985caa9e2da567948e36d7d4ba0185005](https://git.cafe/gitcafe/zig/commit/ce65533985caa9e2da567948e36d7d4ba0185005?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/013efaf13987acfa6b41d40f07900c1ea77f5bda?format=markdown)
