ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
notzmv has joined #crystal-lang
ua_ has quit [Ping timeout: 245 seconds]
human_g33k has quit [Quit: WeeChat 2.3]
szutt has joined #crystal-lang
szutt has quit [Quit: Client closed]
elf_fortrez has joined #crystal-lang
Stephie has quit [Quit: Fuck this shit, I'm out!]
Stephie has joined #crystal-lang
SamantazFox has joined #crystal-lang
SamantazFox has quit [Ping timeout: 248 seconds]
HumanG33k has joined #crystal-lang
<FromGitter> <rymiel:rymiel.space> Screenshot_20210814-164646.png (https://gitter.ems.host/_matrix/media/v1/download/rymiel.space/bTLiznikxHluODKSxkfBIqtK)
<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> @alex-kampa: what works well now: create a BitArray of desired size , convert it to slice https://crystal-lang.org/api/1.1.1/BitArray.html#to_slice:Bytes-instance-method, and copy a random slice to that slice
<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> @oprypin:matrix.org so using Random::Secure.rand(2) instead of Random::Secure.random_bytes(b) is much slower:
<FromGitter> <oprypin:matrix.org> @alex-kampa oh don't use random secure then
<FromGitter> <alex-kampa> ok, with just Random, the performance is very different, your method is faster:
<FromGitter> <alex-kampa> bit of an inconsistency: ⏎ Random::Secure.rand(2) and Random::Secure.random_bytes(b) ⏎ versus ⏎ Random.rand(2) and Random.new.random_bytes(b) ⏎ ... ... [https://gitter.im/crystal-lang/crystal?at=6118282d025d436054cdec28]
<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 )
<FromGitter> <Blacksmoke16> It's from record
<hightower3> Ah yes, #copy_with, https://crystal-lang.org/api/1.1.1/toplevel.html#record(name,*properties)-macro
<hightower3> interesting that it only exists on `record`. Thanks
<hightower3> or kinda expected, since it's guaranteed what the constructor is
ur5us_ has joined #crystal-lang
SamantazFox has quit [Ping timeout: 248 seconds]
<hightower3> https://github.com/crystallabs/gpm.cr <- shard for gpm (console) mouse support in Crystal