Skip to content

Secure Source of Randomness #23

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/io/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
BytesIO,
StringIO,
)
import random
import string

import numpy as np
Expand All @@ -19,6 +18,7 @@
)

from ..pandas_vb_common import BaseIO
import secrets


class ToCSV(BaseIO):
Expand Down Expand Up @@ -364,7 +364,7 @@ class ReadCSVFloatPrecision(StringIORewind):

def setup(self, sep, decimal, float_precision):
floats = [
"".join([random.choice(string.digits) for _ in range(28)])
"".join([secrets.choice(string.digits) for _ in range(28)])
for _ in range(15)
]
rows = sep.join([f"0{decimal}{{}}"] * 3) + "\n"
Expand Down
5 changes: 2 additions & 3 deletions pandas/plotting/_matplotlib/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import annotations

import random
from typing import TYPE_CHECKING

from matplotlib import patches
Expand All @@ -17,6 +15,7 @@
maybe_adjust_figure,
set_ticks_props,
)
import secrets

if TYPE_CHECKING:
from collections.abc import Hashable
Expand Down Expand Up @@ -300,7 +299,7 @@ def bootstrap_plot(
# TODO: is the failure mentioned below still relevant?
# random.sample(ndarray, int) fails on python 3.3, sigh
data = list(series.values)
samplings = [random.sample(data, size) for _ in range(samples)]
samplings = [secrets.SystemRandom().sample(data, size) for _ in range(samples)]

means = np.array([np.mean(sampling) for sampling in samplings])
medians = np.array([np.median(sampling) for sampling in samplings])
Expand Down