Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit 5f62fd8

Browse files
committed
Use SmallRng instead of thread_rng which is not available on no_std
The RNG is seeded from the current time to yield different random values on each invocation. Signed-off-by: Daniel Egger <[email protected]>
1 parent 5d8bade commit 5f62fd8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

macros/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ extern crate rand;
66
extern crate quote;
77
extern crate proc_macro2;
88
extern crate syn;
9+
extern crate core;
910

11+
use core::mem;
1012
use proc_macro2::Span;
1113
use rand::Rng;
14+
use rand::SeedableRng;
15+
use std::time::{SystemTime, UNIX_EPOCH};
1216
use syn::{FnArg, Ident, Item, ItemFn, ItemStatic, ReturnType, Stmt, Type, Visibility};
1317

1418
use proc_macro::TokenStream;
@@ -492,7 +496,9 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
492496

493497
// Creates a random identifier
494498
fn random_ident() -> Ident {
495-
let mut rng = rand::thread_rng();
499+
let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
500+
let seed = [seed, seed];
501+
let mut rng = rand::rngs::SmallRng::from_seed( unsafe { mem::transmute(seed) } );
496502
Ident::new(
497503
&(0..16)
498504
.map(|i| {

0 commit comments

Comments
 (0)