daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //   http://static.rust-lang.org/doc/master/std/rand/trait.Rng.html
  2.  
  3. 01  use std::rand;
  4. 02  use std::rand::Rng;
  5. 03
  6. 04  fn main() {
  7. 05    let mut rng = rand::task_rng();
  8. 06    let n: uint = rng.gen_range(0u, 10);
  9. 07    println!("{}", n);
  10. 08    let m: float = rng.gen_range(-40.0, 1.3e5);
  11. 09    println!("{}", m);
  12. 10  }
  13.    
  14. test_rand002.rs:6:17: 6:39 error: type `@mut std::rand::IsaacRng` does not
  15. implement any method in scope named `gen_range`
  16. test_rand002.rs:6    let n: uint = rng.gen_range(0u, 10);
  17.                                ^~~~~~~~~~~~~~~~~~~~~~
  18. test_rand002.rs:8:18: 8:46 error: type `@mut std::rand::IsaacRng` does not
  19. implement any method in scope named `gen_range`
  20. test_rand002.rs:8    let m: float = rng.gen_range(-40.0, 1.3e5);
  21.                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. error: aborting due to 2 previous errors
  23.    
  24. use std::rand;
  25. use std::rand::Rng;
  26.  
  27. fn main() {
  28.    let mut rng = rand::task_rng();
  29.    let x: uint = rng.gen();
  30.    println!("{}", x);
  31.    println!("{:?}", rng.gen::<(f64, bool)>());
  32. }
  33.    
  34. use std::rand::{task_rng, Rng};
  35.  
  36. fn main() {
  37.     // a number from [-40.0, 13000.0)
  38.     let num: f64 = task_rng().gen_range(-40.0, 1.3e4);
  39.     println!("{}", num);
  40. }
  41.    
  42. extern crate rand;
  43. use rand::Rng;
  44. fn main(){
  45.     let num = rand::thread_rng().gen_range(0, 100);
  46.     println!("{}", num);
  47. }
  48.    
  49. extern crate rand;
  50. use rand::distributions::{IndependentSample, Range};
  51.  
  52. fn main() {
  53.   let step =  Range::new(0, 50);
  54.   let mut rng = rand::thread_rng();
  55.   let choice = step.ind_sample(&mut rng);
  56.   println!("{}", choice);
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top