Skip to content

2D simplex noise uses mod(i,255) instead of mod(i,256), skipping permutation entry #1223

@sbryngelson

Description

@sbryngelson

Bug

In src/pre_process/m_simplex_noise.fpp lines 208-209, the permutation table index wrapping uses mod(i, 255):

ii = mod(i, 255)    ! range 0..254
jj = mod(j, 255)    ! range 0..254

The permutation table p_vec has 256 entries (indices 0-255). mod(i, 255) gives range 0-254, so p_vec(255) is never accessed. This subtly biases the noise distribution by systematically excluding one permutation entry.

The standard simplex noise algorithm uses iand(i, 255) (bitwise AND), which gives the correct 0-255 range and is also faster than modular division.

Fix

PR #1218

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions