Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rand 0.9 beta error - isize: SampleUniform is not satisfied #1540

Closed
pendruct opened this issue Nov 27, 2024 · 4 comments
Closed

rand 0.9 beta error - isize: SampleUniform is not satisfied #1540

pendruct opened this issue Nov 27, 2024 · 4 comments

Comments

@pendruct
Copy link

i used to be able to do rng.gen with isize but not anymore

@pendruct pendruct added the X-bug Type: bug report label Nov 27, 2024
@dhardy dhardy removed the X-bug Type: bug report label Nov 27, 2024
@dhardy
Copy link
Member

dhardy commented Nov 27, 2024

This is intentional: #1487.

Why do you need this?

@pendruct
Copy link
Author

pendruct commented Nov 27, 2024

oh okay! so is this a breaking change then? i didnt see it mentioned in changelog but maybe im missing something.

i am making a game with a 2d maze and i use it for my teleport function:

fn teleport_destination_node(grid: &Grid, player_row: usize) -> Option<(usize, usize)> {
  let delta = roll(-2..13);
  let dest_row = player_row.saturating_add_signed(delta).clamp(0, grid.height.saturating_sub(1));

  for col in 0..grid.width {
    if grid.node(dest_row, col).is_main {
      return Some((dest_row, col));
    }
  }

  None
}

it's not that important though so i can just refactor it. thanks for the info!

im using usize and isize because im doing indexing into 2d arrays and thats what rust asks for

was able to get around it by doing this (since you can make an isize from an i16):

let delta: isize = roll(-2i16..13i16).into();

@dhardy
Copy link
Member

dhardy commented Nov 28, 2024

Then I recommend you pick a fixed size integer like i16, yes.

The reason we did this was because of various complaints of a hidden portability hazard: generating a random usize / isize in rand v0.8 will produce different results on 32-bit and 64-bit machines.

It comes under this entry in the changelog, but you're right that it's unclear:

Add UniformUsize and use to make Uniform for usize portable (#1487)

@dhardy dhardy closed this as completed Nov 28, 2024
@pendruct
Copy link
Author

sure thing! thanks again for the replies! good luck with 0.9! looking forward to it!! 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants