<FromGitter>
<rymiel:rymiel.space> love me a good tower of question marks
<FromGitter>
<rymiel:rymiel.space> guess it's minimal repro time
<FromGitter>
<jrei:matrix.org> Do you use inheritance with generics?
<FromGitter>
<oprypin:matrix.org> Emilia (https://matrix.to/#/@rymiel:rymiel.space): the question marks are when there's no debug info. you can build crystal compiler (`git clone`, `make`) and use that directly on your program, then there will be a stack trace
elf_fortrez has quit [Ping timeout: 246 seconds]
<yxhuvud>
I'm quite curious how it ends up in a Java Bytecode exception though .P
hightower2 has joined #crystal-lang
hightower3 has joined #crystal-lang
hightower2 has quit [Ping timeout: 268 seconds]
SamantazFox has joined #crystal-lang
hexology has quit [Quit: hex on you ...]
repo has quit [Ping timeout: 272 seconds]
repo has joined #crystal-lang
pusewic|away has quit [Ping timeout: 240 seconds]
<FromGitter>
<alex-kampa> There is a "random_bytes" method in both Random and Random::Secure. Would it make sense to implement a "random_bits" method that would return a String?
kevinsjoberg has quit [Ping timeout: 256 seconds]
<FromGitter>
<alex-kampa> (of course it does not take much effort to do this using random_bytes...)
willamin has quit [Ping timeout: 276 seconds]
r0bby has quit [Ping timeout: 258 seconds]
kevinsjoberg has joined #crystal-lang
Liothen has quit [Ping timeout: 240 seconds]
pusewic|away has joined #crystal-lang
r0bby has joined #crystal-lang
willamin has joined #crystal-lang
<FromGitter>
<oprypin:matrix.org> @alex-kampa: the use case for it must be very rare. can you name yours?
<FromGitter>
<alex-kampa> series of coin tosses
Liothen has joined #crystal-lang
<FromGitter>
<oprypin:matrix.org> @alex-kampa: just call random(2) repeatedly
<FromGitter>
<alex-kampa> @oprypin:matrix.org - do you think performance will be similar to using random_bytes? Anyway, I'll check.
<yxhuvud>
are you doing monte carlo simulations?
<FromGitter>
<alex-kampa> that's one use case yes, but there are also maths problems where this is useful.
<yxhuvud>
right. Then I kinda see why you'd want to make the most out of the calls to rand, but why do you want a random string over random_bytes?
<FromGitter>
<oprypin:matrix.org> anyway, if anything, maybe it'd return `BitArray`
<FromGitter>
<oprypin:matrix.org> then do `BitArray.each`
<FromGitter>
<oprypin:matrix.org> (which might actually be slower than calling random(2) repeatedly; `BitArray.each` seems totally not optimized)
<FromGitter>
<alex-kampa> my specific use case is to find the first occurrence of a particular bit sequence, so if I have a string I can use a regex to find it
<FromGitter>
<oprypin:matrix.org> @alex-kampa: sorry but I really do think this is super rare, despite your use case being valid.
<FromGitter>
<oprypin:matrix.org> I haven't seen precedent in other programming languages.
<FromGitter>
<oprypin:matrix.org> for speed i have another idea
<FromGitter>
<oprypin:matrix.org> `String.build |io|` and inside it call `random_bytes` and for each byte call `byte.to_s(2, io)`
<FromGitter>
<alex-kampa> Yes no problem, I've already implemented it, was just wondering whether this may be more generally useful.
<yxhuvud>
oprypin: don't you end up with potentially invalid strings then?
<FromGitter>
<alex-kampa> Re speed - ok will try this too @oprypin:matrix.org
<FromGitter>
<oprypin:matrix.org> yxhuvud, what's invalid? all byte strings convert to all bit strings. save for size.
<yxhuvud>
oprypin: the strings wouldn't be guaranteed to be valid utf8, right? and that could brake later regexp matching or whatever?
<FromGitter>
<oprypin:matrix.org> to_s(2) is 011010101010000
<FromGitter>
<oprypin:matrix.org> you can rest assured I'd never recommend forming an invalid string
<yxhuvud>
ah, you mean taking one bit per char. Yeah, that will work though it will be not very compact :)
<FromGitter>
<oprypin:matrix.org> well this not compact thing is what they want
<FromGitter>
<alex-kampa> exactly. string of coin tosses.
<FromGitter>
<rymiel:rymiel.space> yxhuvud, it's a java bytecode parser/analyzer because i didn't find a tool that suited my exact needs so i wrote my own. Only after i started, did i realize that a java bytecode parser is essentially just a fully-fleged java virtual machine sooo that's what i have now
<FromGitter>
<alex-kampa> anyway, was fun to try this out, thanks for your input @oprypin:matrix.org
<FromGitter>
<oprypin:matrix.org> @alex-kampa: regarding what you say is an inconsistency: it is intentional. Random::Secure behaves like an instance of Random. it is global.
<FromGitter>
<alex-kampa> then why not Random.new.rand(2) ?
<hightower3>
Hey wasn't there some method on structs that allowed one to basically make a copy of the struct, with some fields changed? Like, mystruct.clone( some_field: new_value )