Skip to content

RNG parameter intuitiveness #2

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

Open
zmeyc opened this issue Jan 13, 2018 · 1 comment
Open

RNG parameter intuitiveness #2

zmeyc opened this issue Jan 13, 2018 · 1 comment

Comments

@zmeyc
Copy link

zmeyc commented Jan 13, 2018

It's a bit confusing that Int.random(0, 100) can return 100 as well, ranges usually exclude the second value. Lot more confusing that Int.random(range: 0..<1) returns 0...1. And inclusive range (...) is not supported at all.

(lldb) p Int.random(range: 0..<1)
(Int) $R24 = 0
(lldb) p Int.random(range: 0..<1)
(Int) $R25 = 1

Also Double.random() has a default of 0.0...100.0 while usually 0..<1 would be expected. Would you like me to submit a PR to adjust these?

@s1ddok
Copy link
Member

s1ddok commented Jan 15, 2018

Well, while I agree with Int.random(0, 100) returning 0...99 may be conventional in a lot of frameworks (including C# ones etc) I would still would like to see it returning 0...100, because it seems more rational to me.

Int.random(range: 0..<1) returns 0...1

I would treat this as a library bug

Double.random() has a default of 0.0...100.0 while usually 0..<1 would be expected

Yes, this is also a bad pitfall.

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

No branches or pull requests

2 participants