Rust

外部包的导入

2019-10-26  本文已影响0人  空乱木

0-参考链接
https://rust-random.github.io/rand/rand/index.html

1- cargo.toml 引用导入
[dependencies]
rand = “0.7.2"

2- 代码use

use rand::prelude::*;

fn main() {

    if rand::random() { // generates a boolean
        // Try printing a random unicode code point (probably a bad idea)!
        println!("char: {}", rand::random::<char>());
    }

    let mut rng = rand::thread_rng();
    let y: f64 = rng.gen(); // generates a float between 0 and 1

    let mut nums: Vec<i32> = (1..100).collect();
    nums.shuffle(&mut rng);
    println!("Hello, world!");
}

3- 日志

[@zhous-MBP-2:] ~/blockchain/rust/hello_cargo/src $ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running /Users/zhouhe/blockchain/rust/hello_cargo/target/debug/hello_cargo
char: 񣞲
Hello, world!

上一篇下一篇

猜你喜欢

热点阅读