-
-
Notifications
You must be signed in to change notification settings - Fork 481
Description
This is related to pull request #109. I've opened this as a new issue as I think this is something that needs proper tracking.
When working with highly concurrent modern data structures, it's often important to be able to pick a (hyper) thread local random number very, very quickly for a small value - a u32 or u64 or usize, for example. The RDRAND instruction on Ivy Bridge and later CPUs makes this straightforward, but one then needs a fallback - and the rand crate provides ThreadRng. This, however, eats into thread TLS space (threads aren't necessarily present on low-end platforms), requires initialisation, etc.
It'd be far more elegant to have perhaps a create compilation feature, or even better, when #[cfg(target_feature)] lands, to be able to have the OsRng switch over to RDRAND instead of using a syscall, and then to be able to eliminate ThreadRng set up entirely.
RDRAND is also a preferable source of randomness in early Unix system init, and in systems using #[no_std].
I've recently created a temporary stop gap crate hyper-thread-random to provide randomness for hyper threads with RDRAND and a fallback to ThreadRng, but it seems only logical that all things randomness-related are better 'made at home' in the rand crate.