Skip to content
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

Added random function #401

Merged
merged 5 commits into from
Mar 19, 2024
Merged

Added random function #401

merged 5 commits into from
Mar 19, 2024

Conversation

mrkbac
Copy link
Contributor

@mrkbac mrkbac commented Mar 16, 2024

This PR add a random() function.

Example output:

>>> 10 * random() // floor

  floor(10 × random())

    = 6 

Let me know if I should change anything!

numbat/src/ffi.rs Outdated Show resolved Hide resolved
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Thank you!

@sharkdp sharkdp merged commit 3509756 into sharkdp:master Mar 19, 2024
15 checks passed
@Bzero
Copy link
Contributor

Bzero commented Mar 19, 2024

I am just a minute too late with my comment but I think it might be worth to think about if the rand() function should take min and max arguments.

For many applications one will need to scale the default [0, 1) interval and to me rand(a, b) looks more convenient than rand() * (b - a) + a.

@triallax
Copy link
Contributor

We don't have optional parameters at the moment so we might want to leave it until that's implemented.

@sharkdp
Copy link
Owner

sharkdp commented Mar 20, 2024

@Bzero Thank you for your comment. I had similar thoughts before merging. But I was hoping that we could now implement a function like rand(a, b) or randint(from, to) using that one source of randomness random(). If that turns out to be tricky (e.g. because of subtle biases) , let's add a more FFI functions or rethink this one.

@mrkbac mrkbac deleted the random branch March 20, 2024 11:35
@Bzero
Copy link
Contributor

Bzero commented Mar 20, 2024

Yes that sounds reasonable, it would probably make sense to implement these features in a module in numbat itself.

@sharkdp
Copy link
Owner

sharkdp commented Mar 20, 2024

to implement these features in a module in numbat itself

Yes, absolutely. That's what I meant. Should have mentioned it. In general, I try to keep the FFI as small as possible. And everything we implement in Numbat itself is a good test for the language.

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