Skip to content

Bias of random.integers() with int8 dtype #14774

@wrwrwr

Description

@wrwrwr

Output of integers() with dtype=int8 appears to be less uniform that one could expect it to.

import matplotlib.pyplot as plt
import numpy as np

samples = np.random.default_rng().integers(31, size=1111111, dtype=np.int8)
values, counts = np.unique(samples, return_counts=True)
plt.vlines(values, 0, counts)
plt.show()

random-int8

Similar periodicity shows up with various static seeds and MT19937; flipping the use_masked flag in random_bounded_uint8_fill() results in all values having approximately equal frequencies.
Same for 1.17 and 1.18.0.dev0+c10d66a 3.7.3 (default, Oct 7 2019, 12:56:13) [GCC 8.3.0].

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions