How can we generate random numbers in Scrypto if floating point libraries are not allowed be used? I want to be able to generate unique IDs for NFTs.
There are 2 ways to solve this:
vec.len() + 1
as the generated ID, making things more trivial.Runtime::generate_uuid
which is a generated number format in Uuid which should guarantee uniquenessWe can also generate values given a max range:
fn get_random(end: usize) -> usize {
let num = Runtime::generate_uuid();
(num % end as u128) as usize
}
// prints number between 0 - 5
info!("{}", get_random(5));