Skip to content

Conversation

@malkoG
Copy link
Contributor

@malkoG malkoG commented Oct 26, 2019

Functions for integers, functions for sequences works. But, Real-valued distributions is still working on progress.

}

#[pymethod]
fn seed(&self, n: Option<usize>, vm: &VirtualMachine) -> PyResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make n an Option<u64> to avoid the cast

right = [2, 7, 3, 5, 8, 4, 6, 9, 0, 1]
random.shuffle(left)

assert all([l == r for l, r in zip(left, right) ])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this same as assert left == right? Same for other tests too.

#[pyclass(name = "Random")]
#[derive(Debug)]
struct PyRandom {
rng: RefCell<SmallRng>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly recommend to use StdRng as a default instead, it is a much safer choice, because it is not predictable.

Copy link
Member

@coolreader18 coolreader18 Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be possible to have an enum inside the RefCell with both StdRng and SmallRng as variants, and only switch to SmallRng when seed is called.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SmallRng is not the Mersenne Twister, so it does not make sense to switch to it for compatibility with CPython. Other than that, I agree!

None => SmallRng::from_entropy(),
Some(n) => {
let seed = n as u64;
SmallRng::seed_from_u64(seed)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to support larger seeds (via bigints), but this requires more work and could be done later (likely in a backwards incompatible way).

@coolreader18
Copy link
Member

@malkoG I'd be willing to take over this PR, could I have your permission to use the code you've written as a base?

@malkoG
Copy link
Contributor Author

malkoG commented Jan 29, 2020

Sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants