How to generate a different random number in one round

I have a code like this

use rand::prelude;
use std::fs;
fn replace(path : String) {
 for i in read_to_string(path).split_witespace().collect::<Vec<&str>>() {
     if i == "" {
      continue;
}
path = path.replace(i,random::<i16>();)
}
}
fn main() {
   replace("xxx.txt".into());
}

but,when I cat xxx.txt.I see that the numbers were same.
How to generate different?

Please use rustfmt to fix your code formatting. Inconsistent indentation makes the code hard to read.

If I were to fix the syntax, mutability, type, and borrowing errors which prove you never tested this code, this

still wouldn't do anything like editing xxx.txt. How could it? You only read_to_string once and never write to the file at all. Moreover, path is a variable that contains the file name, not its contents.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.