-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_jitter.pl
61 lines (54 loc) · 1.1 KB
/
gen_jitter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl
use strict;
use constant jitter => 3.0;
my $s = rand();
srand (0);
my @packets;
for (my $i = 0; $i < 10; $i++)
{
my @packet = ();
# build the packet: 10 transitions? Sure, why not.
for (0..16)
{
push @packet, int(jitter*2 + 4*int(1+rand()*5));
}
push @packets, \@packet;
}
srand($s);
for (my $i = 0; $i < 10; $i++)
{
my @packet = @{ $packets[$i] };
my @times;
my $t = 0.0;
for (@packet)
{
$t += $_;
push @times, $t;
}
open(OUT, ">key_$i");
open(OUTB, ">key_$i.bin");
# Print the packet out 10 times, with some jitter;
for (0..100)
{
my @jittered_times = map
{
my $d = (2.0*rand()*jitter)- jitter;
$d + $_;
}
@times;
my $t = 0;
print OUT "{ ";
for (@jittered_times)
{
my $n = int ($_ - $t);
print OUT $n." ";
$t = $_;
print OUTB (sprintf "%c%c", ($n>>8)&255,
($n&255));
}
print OUT " }\n";
print OUTB (sprintf "%c%c", 255, 255);
}
close(OUT);
close(OUTB);
}