Overflow due to shift right

Line 45:30 is the problem or line eight.

        //println!("[Server] Game: generating chunk @ {:?}", pos);
        let (cx, cy, cz) = (pos[0], pos[1], pos[2]);
        let mut chunk = Chunk::empty();
        let seed = ((cx * 4242424242 + cz) % 1_000_000_007).abs();
        let mut seed_array = [0; 32];
        for i in 0..32 {
            seed_array[i] = ((seed >> (i * 8)) % 256) as u8;
        } 

seed_array[i] = ((seed >> (i * 8)) % 256) as u8;
error is thread cunnamed panicked at 'attempt to shift right with over flow. src\sim worldgen.rs:45:30

What's your question?

you can make code blocks with

```rust
// your code here
// the rust tag above is optional
```

the right arrow is for quotes

> this is a quote

will turn into

this is a quote

You're trying to shift seed right by up to 8*31 bits, which is more bits than any integer type in Rust has. This is a bug.

2 Likes