hyper_thread_random/generate_hyper_thread_safe_random_u64.rs
1// This file is part of hyper-thread-random. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/hyper-thread-random/master/COPYRIGHT. No part of hyper-thread-random, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2018 The developers of hyper-thread-random. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/hyper-thread-random/master/COPYRIGHT.
3
4
5/// Generates a random u64 for the current hyper thread.
6#[cfg(all(target_arch = "x86", target_feature = "rdrand"))]
7#[inline(always)]
8pub fn generate_hyper_thread_safe_random_u64() -> u64
9{
10 generate!(u64, ::std::arch::x86::_rdrand64_step)
11}
12
13/// Generates a random u64 for the current hyper thread.
14#[cfg(all(target_arch = "x86_64", target_feature = "rdrand"))]
15#[inline(always)]
16pub fn generate_hyper_thread_safe_random_u64() -> u64
17{
18 generate!(u64, ::std::arch::x86_64::_rdrand64_step)
19}
20
21/// Generates a random u64 for the current hyper thread.
22#[cfg(not(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "rdrand")))]
23pub fn generate_hyper_thread_safe_random_u64() -> u64
24{
25 thread_rng().next_u64()
26}