📜  Rust 中的随机游走 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:05.851000             🧑  作者: Mango

代码示例1
pub fn calc_random_walk_steps(r:i64)->i64{    let directions = [[-1,0],[1,0],[0,-1],[0,1]];    let mut position = [0i64,0];    let mut steps = 0;     while (position[0].abs() + position[1].abs()) < r {        let dir_index = rand::random::()%4;        position[0]+=directions[dir_index][0];        position[1]+=directions[dir_index][1];        steps+=1;    }    steps}