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

0x00:0xff is empty #6262

Closed
johnmyleswhite opened this issue Mar 25, 2014 · 8 comments
Closed

0x00:0xff is empty #6262

johnmyleswhite opened this issue Mar 25, 2014 · 8 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@johnmyleswhite
Copy link
Member

[convert(Uint8, 0):convert(Uint8, 255)]

On my system, this produces seemingly random output.

@jiahao
Copy link
Member

jiahao commented Mar 25, 2014

Possibly related:

julia> for i in 0x00:0xff #no output
        println(i)
       end

julia> length(0x00:0xff)
256

@johnmyleswhite
Copy link
Member Author

I think I raised an issue about that exact behavior at one point in the past, but thought it had been fixed once before.

@StefanKarpinski
Copy link
Member

I noticed this yesterday for Uint16.

@ivarne
Copy link
Member

ivarne commented Mar 25, 2014

Isn't this a dup of #5550?

# base/ranges.jl
done{T<:Integer}(r::Range1{T}, i) = i==oftype(T, r.start+r.len)

julia> dump(convert(Uint8, 0):convert(Uint8, 255))
Range1{Uint8} 
  start: Uint8 0
  len: Int64 256

julia> oftype(Uint8, 0+256)
0x00

The iteration seems to be done before it has started because of overflow. The allocated array will not be written to and thus appear random.

@ivarne
Copy link
Member

ivarne commented Mar 25, 2014

julia> done(a,start(convert(Uint8, 0):convert(Uint8, 255)))
true

@simonster
Copy link
Member

#5550 looks related but not quite the same. I believe #6266 fixes this without breaking anything.

@mschauer
Copy link
Contributor

Yes, #5550 not quite, because in random.jl a range is first transformed to an alternative representation where the length is saved as small unsigned integer and not as Int64 like here (this representation is a part of the type RandIntGen, see there).

@JeffBezanson JeffBezanson changed the title Randomness in Uint8 ranges? 0x00:0xff is empty Mar 26, 2014
@JeffBezanson
Copy link
Member

This is also part of #5585, and is fixed on my branch jb/newrange1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

7 participants