Generate random seeds.
This uses NumPy's random number support to create seeds from available sources of
entropy. They are not guaranteed to be cryptographically secure, but are suitable
for seeding simulation plugins that need random numbers.
Source code in openstb/simulator/cli/seed.py
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 | @click.command
@click.option(
"--number", "-n", default=1, metavar="N", help="The number of seeds to generate."
)
@click.option(
"--output",
"-o",
type=click.File("w"),
default="-",
show_default=False,
help="Where to write the seeds. By default they are printed to the terminal.",
)
@click.option(
"--digits",
"-d",
type=int,
default=None,
show_default=False,
help=(
"The maximum number of digits to output. By default all generated digits are "
"output."
),
)
def seed(number, output, digits):
"""Generate random seeds.
This uses NumPy's random number support to create seeds from available sources of
entropy. They are not guaranteed to be cryptographically secure, but are suitable
for seeding simulation plugins that need random numbers.
"""
if number < 1:
raise click.ClickException("number of seeds cannot be less than one")
if digits is not None and digits < 1:
raise click.ClickException("number of digits cannot be less than one")
for i in range(number):
seedstr = str(generate_seed())
if digits is not None:
seedstr = seedstr[:digits]
output.write(seedstr)
output.write("\n")
|