Function array_rand

Source
pub fn array_rand<T>(array: &Vec<T>) -> Option<usize>
Expand description

Pick one random key out of a vector

§Description

Picks one entry out of a vector, and returns the index of the random entry.

@TODO: It uses a pseudo random number generator that is not suitable for cryptographic purposes.

§Examples

Example #1 array_rand() example

use phpify::array::array_rand;

let input = vec!["Neo", "Morpheus", "Trinity", "Cypher", "Tank"];
let rand_key = array_rand(&input).unwrap();

assert_eq!(rand_key <= 4, true);