line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Random::Source::Weak::rand; |
2
|
|
|
|
|
|
|
# ABSTRACT: Use C to create random bytes |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
23643
|
use Moo; |
|
3
|
|
|
|
|
14635
|
|
|
3
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
3022
|
use bytes; |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
20
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends qw( |
11
|
|
|
|
|
|
|
Crypt::Random::Source::Weak |
12
|
|
|
|
|
|
|
Crypt::Random::Source::Base |
13
|
|
|
|
|
|
|
); |
14
|
3
|
|
|
3
|
|
2070
|
use namespace::clean; |
|
3
|
|
|
|
|
13487
|
|
|
3
|
|
|
|
|
20
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
1
|
23
|
sub rank { -100 } # slow fallback |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
1
|
34
|
sub available { 1 } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub seed { |
21
|
0
|
|
|
0
|
1
|
0
|
my ( $self, @args ) = @_; |
22
|
0
|
|
|
|
|
0
|
srand( unpack("%L*", @args) ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get { |
26
|
2
|
|
|
2
|
1
|
1214
|
my ( $self, $n ) = @_; |
27
|
2
|
|
|
|
|
35
|
pack "C*", map { int rand 256 } 1 .. $n; |
|
2000
|
|
|
|
|
2901
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding UTF-8 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Crypt::Random::Source::Weak::rand - Use C to create random bytes |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 VERSION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
version 0.11 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Crypt::Random::Source::Weak::rand; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $p = Crypt::Random::Source::Weak::rand->new; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$p->get(1024); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This is a weak source of random data, that uses Perl's builtin C |
55
|
|
|
|
|
|
|
function. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 seed @blah |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Sets the random seed to a checksum of the stringified values of C<@blah>. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
There is no need to call this method unless you want the random sequence to be |
64
|
|
|
|
|
|
|
identical to a previously run, in which case you should seed with the same |
65
|
|
|
|
|
|
|
value. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 get $n |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Produces C<$n> random bytes. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SUPPORT |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Bugs may be submitted through L |
74
|
|
|
|
|
|
|
(or L). |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This software is copyright (c) 2008 by Yuval Kogman. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
85
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |