[−][src]Function solana_rbpf::helpers::rand
pub fn rand(
min: u64,
max: u64,
unused3: u64,
unused4: u64,
unused5: u64,
_context: &mut HelperContext,
_ro_regions: &[MemoryRegion],
_rw_regions: &[MemoryRegion]
) -> Result<u64, Error>
Returns a random u64 value comprised between min
and max
values (inclusive). Arguments 3 to
5 are unused.
Relies on rand()
function from libc, so libc::srand()
should be called once before this
helper is used.
Examples
extern crate libc; extern crate solana_rbpf; extern crate time; use solana_rbpf::helpers; use solana_rbpf::memory_region::MemoryRegion; unsafe { libc::srand(time::precise_time_ns() as u32) } let regions = [MemoryRegion::default()]; let n = helpers::rand(3, 6, 0, 0, 0, &mut None, ®ions, ®ions).unwrap(); assert!(3 <= n && n <= 6);