Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Bit-vector compression

by jwkrahn (Abbot)
on Mar 01, 2022 at 23:32 UTC ( [id://11141741]=note: print w/replies, xml ) Need Help??


in reply to Bit-vector compression

my $i = int(rand(length($str)-1));

You have an off-by-one problem there.

Say that $str has a length of 8 and so has characters at positions 0 through 7.

length($str)-1 will produce random numbers in the range 0 through 6, one less than the length of the string.

Update:

This produces the same result as your pack_str subroutine:

sub pack_str { my ( $s ) = @_; return pack 'B*', $s; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11141741]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found