You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My aim here was to generate a random string of random length with a maximum length of 255 letters.
So, I tried the following:
using Random
s = randstring(rand(UInt8))
which errors with:
ERROR: MethodError: no method matching Random.UnsafeView(::Ptr{UInt8}, ::UInt8)
Closest candidates are:
Random.UnsafeView(::Ptr{T}, ::Int64) where T
@ Random C:\Users\thvt\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\Random\src\RNGs.jl:471
Stacktrace:
[1] randstring(r::TaskLocalRNG, chars::Vector{UInt8}, n::UInt8)
@ Random C:\Users\thvt\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\Random\src\misc.jl:79
[2] randstring(n::UInt8)
@ Random C:\Users\thvt\AppData\Local\Programs\Julia-1.10.2\share\julia\stdlib\v1.10\Random\src\misc.jl:90
[3] top-level scope
@ REPL[23]:1
If explicitly type-casting the result of rand() to Int64 (but not any other Integer type!), it works as expected:
using Random
s = randstring(Int64(rand(UInt8)))
It's not super transparent why that would be necessary and I would have expected it to "just work" with an UInt8 (or any other type <: Integer for that matter) as well.
Maybe one of the methods involved here is overly specific?
Output of versioninfo():
Julia Version 1.10.2
Commit bd47eca2c8 (2024-03-01 10:14 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 24 × 12th Gen Intel(R) Core(TM) i7-12850HX
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, alderlake)
Threads: 24 default, 0 interactive, 12 GC (on 24 virtual cores)
The text was updated successfully, but these errors were encountered:
FixesJuliaLang#54397
What remains is that the effectively allowed input still needs
to be convertible to `Int`. So things like `typemax(Int128)` won't
work, and neither will negative values.
My aim here was to generate a random string of random length with a maximum length of 255 letters.
So, I tried the following:
which errors with:
If explicitly type-casting the result of rand() to Int64 (but not any other Integer type!), it works as expected:
It's not super transparent why that would be necessary and I would have expected it to "just work" with an UInt8 (or any other type <: Integer for that matter) as well.
Maybe one of the methods involved here is overly specific?
Output of versioninfo():
The text was updated successfully, but these errors were encountered: