Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just followed what the code did before (it just had the values incorrect). Why would the r be needed, it actually is not even used (I don't know why the function even has the argument, it seems rather misleading)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no expert on Julia's RNG code, but I think this might have been an oversight in the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way rand is meant to be used, here, is the 1-argument form, i.e.:
rand(Char), and that it is simply using the 1-argument form there also:
I'm pretty sure it is correct both in the original code, and in my update.
Thanks for reviewing the code though, the dropping of r bothers me too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, and hi david ;-)
rand(r, 0:0x10f7ff)
gives reproducible random numbers and has side effects onr
,rand(0:0x10f7ff)
is not reproducible in a reasonable way and has side effects onGLOBAL_RNG
.rand(r::AbstractRNG, ::Type{Char})
should not affectGLOBAL_RNG
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviddelaat is right, the
rand
Range
needs to be parameterized by theAbstractRNG
. I'll add the fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain... I really know nothing about the way abstract ranges work, or GLOBAL_RNG...
I was just fixing the Unicode issues!
Maybe @jakebolewski should fix the range issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I totally understand your question, but the change Jake made in 7efbc01 isn't really specific to ranges or the RNG. It's an idiom for functions that interact with global state (like the GLOBAL_RNG or STDOUT). For example, the print function has one fallback method:
And then all custom types define methods
print(io::IO, x::MyType)
, and within those methods they should only call the two-arg print methods, explicitly usingio
instead of defaulting back to STDOUT. This allows you to easily collect the output in, e.g., an IOBuffer without worrying about stuff leaking out to STDOUT.The same applies to RNGs, since they are also a global that mutates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks, now that makes sense!