ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
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> <> Screenshot_20210814-164646.png (
<FromGitter> <> love me a good tower of question marks
<FromGitter> <> guess it's minimal repro time
<FromGitter> <> Do you use inheritance with generics?
<FromGitter> <> Emilia ( 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> <> @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> <> @alex-kampa: just call random(2) repeatedly
<FromGitter> <alex-kampa> - 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> <> anyway, if anything, maybe it'd return `BitArray`
<FromGitter> <> @alex-kampa: what works well now: create a BitArray of desired size , convert it to slice, and copy a random slice to that slice
<FromGitter> <> then do `BitArray.each`
<FromGitter> <> (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> <> @alex-kampa: sorry but I really do think this is super rare, despite your use case being valid.
<FromGitter> <> I haven't seen precedent in other programming languages.
<FromGitter> <> for speed i have another idea
<FromGitter> <> ` |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
<FromGitter> <> 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> <> to_s(2) is 011010101010000
<FromGitter> <> 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> <> well this not compact thing is what they want
<FromGitter> <alex-kampa> exactly. string of coin tosses.
<FromGitter> <> 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> so using Random::Secure.rand(2) instead of Random::Secure.random_bytes(b) is much slower:
<FromGitter> <> @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 ⏎ ... ... []
<FromGitter> <alex-kampa> anyway, was fun to try this out, thanks for your input
<FromGitter> <> @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 ?
<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,,*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> <- shard for gpm (console) mouse support in Crystal