7
7
from .circt import ir
8
8
from .core import Value
9
9
from .index import index
10
+ from .rtg import rtg
10
11
11
- import typing
12
+ from typing import Union
12
13
13
14
14
15
class Integer (Value ):
@@ -19,13 +20,26 @@ class Integer(Value):
19
20
away during randomization.
20
21
"""
21
22
22
- def __init__ (self , value : typing . Union [ir .Value , int ]) -> Integer :
23
+ def __init__ (self , value : Union [ir .Value , int ]) -> Integer :
23
24
"""
24
25
Use this constructor to create an Integer from a builtin Python int.
25
26
"""
26
27
27
28
self ._value = value
28
29
30
+ def random (lower_bound : Union [int , Integer ],
31
+ upper_bound : Union [int , Integer ]) -> Integer :
32
+ """
33
+ Get a random number in the given range (lower inclusive, upper exclusive).
34
+ """
35
+
36
+ if isinstance (lower_bound , int ):
37
+ lower_bound = Integer (lower_bound )
38
+ if isinstance (upper_bound , int ):
39
+ upper_bound = Integer (upper_bound )
40
+
41
+ return rtg .RandomNumberInRangeOp (lower_bound , upper_bound )
42
+
29
43
def __add__ (self , other : Integer ) -> Integer :
30
44
return index .AddOp (self ._get_ssa_value (), other ._get_ssa_value ())
31
45
@@ -84,7 +98,7 @@ class Bool(Value):
84
98
away during randomization.
85
99
"""
86
100
87
- def __init__ (self , value : typing . Union [ir .Value , bool ]) -> Bool :
101
+ def __init__ (self , value : Union [ir .Value , bool ]) -> Bool :
88
102
"""
89
103
Use this constructor to create a Bool from a builtin Python bool.
90
104
"""
0 commit comments