Skip to content

random_range seems broken #1578

@michalmoc

Description

@michalmoc

Summary

It seems that random_range() always returns its lower bound. I've checked it with debugger, and it seems that value returned from Rng is for unknown reason replaced with 0, and then forced into range.

Rand 0.9.0, Rust 1.84.1, Windows 11.

Code sample

#[test]
fn gen() {
    let mut rng = StepRng::new(1, 1);
    let res = [
        rng.random_range(1..=6),
        rng.random_range(1..=6),
        rng.random_range(1..=6),
    ];
    assert_eq!(res, [1, 2, 3]);
}

results in

assertion `left == right` failed
  left: [1, 1, 1]
 right: [1, 2, 3]

Metadata

Metadata

Assignees

No one assigned

    Labels

    X-bugType: bug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions