]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | # |
2 | # Copyright(c) 2019 Intel Corporation | |
3 | # SPDX-License-Identifier: BSD-3-Clause-Clear | |
4 | # | |
5 | ||
6 | import random | |
7 | import string | |
8 | from ctypes import ( | |
9 | c_uint64, | |
10 | c_uint32, | |
11 | c_uint16, | |
12 | c_int, | |
13 | c_uint | |
14 | ) | |
15 | ||
16 | ||
17 | def generate_random_numbers(c_type, count=1000): | |
18 | type_dict = { | |
19 | c_uint16: [0, c_uint16(-1).value], | |
20 | c_uint32: [0, c_uint32(-1).value], | |
21 | c_uint64: [0, c_uint64(-1).value], | |
22 | c_int: [int(-c_uint(-1).value / 2) - 1, int(c_uint(-1).value / 2)] | |
23 | } | |
24 | ||
25 | values = [] | |
26 | for i in range(0, count): | |
27 | values.append(random.randint(type_dict[c_type][0], type_dict[c_type][1])) | |
28 | return values | |
29 | ||
30 | ||
31 | def generate_random_strings(): | |
32 | values = [] | |
33 | for t in [string.digits, | |
34 | string.ascii_letters + string.digits, | |
35 | string.ascii_lowercase, | |
36 | string.ascii_uppercase, | |
37 | string.printable, | |
38 | string.punctuation, | |
39 | string.hexdigits]: | |
40 | for i in range(0, 100): | |
41 | values.append(''.join(random.choice(t) for _ in range(random.randint(0, 20)))) | |
42 | return values | |
43 | ||
44 | ||
45 | def get_random_ints(c_type): | |
46 | for value in generate_random_numbers(c_type): | |
47 | yield value | |
48 | ||
49 | ||
50 | def get_random_strings(): | |
51 | for value in generate_random_strings(): | |
52 | yield value |