On Tuesday, August 30, 2016 at 3:34:49 PM UTC, Páll Haraldsson wrote:
>
> On Tuesday, August 30, 2016 at 5:26:29 AM UTC, Jacob Yates wrote:
>>
>> I've been working on porting a script I wrote in python to julia and have
>> been having some issues with the script freezing.
>>
>> So pretty much all this script does is generate a random IP address and
>> checks to see if its valid(the Python version will give http error codes)
>> then logs the results for further analysis.
>>
>> function gen_ip()
>> ip = Any[]
>> for i in rand(1:255, 4)
>> push!(ip, i)
>> end
>> global ipaddr = join(ip, ".")
>> end
>>
>
> [..]
>
> println("Bactrace: ", backtrace())
>>
>
> Note, there is a type for IP addresses, done like: ip"127.0.0.1" (should
> also work for IPv6) or:
>
> gen_ip() = IPv4(rand(0:256^4-1)) #not sure why you excluded 0 in 1:255
> (might want to exclude some IPs but not as much as you did?), or used
> global.
>
gen_ip() = IPv4(begin r=rand(1:254); r >= 10 ? r+1 : r end, rand(0:255),
rand(0:255),
rand(0:255))
is possibly what you want. 0.x.x.x and 10.x.x.x are private networks and
you seemed to want to exclude the former, and if also the latter then the
new version does that. I forget, you where excluding 0 for the x-es, isn't
that just plain wrong (except maybe for the last one)?
> http://docs.julialang.org/en/release-0.4/manual/networking-and-streams/
>
> Generally global is bad form, and I'm not sure, but it might have
> something to do with @async not working, as I guess it's not "thread-safe"
> or related..
>
> --
> Palli.
>
>
>
>