1919
2020 Revision History:
2121 September 6, 2019 Version 0.1 Script.
22+
23+ References:
24+ + \cite[From section 'Built-in Functions']{DrakeJr2016b}.
25+ - Available online from Python: Python 3.8.2rc1
26+ documentation: The Python Standard Library:
27+ Built-in Functions at: https://docs.python.org/3/library/functions.html#bin;
28+ February 12, 2020 was the last accessed date.
29+ + \cite{KiteStaff2020}
2230"""
2331
2432__author__ = 'Zhiyang Ong'
@@ -220,9 +228,10 @@ def gen_rand_signal_uniform_distributn(type_of_signal=bv_signal, n=16):
220228 """
221229 return random_signal
222230 # ============================================================
223- ## Method to generate a discrete-time random signal/process
224- # for "n" values, using another method from the random
225- # module of the Python Standard Library.
231+ ## Method to generate a bit vector -based discrete-time
232+ # random signal/process for "n" values, using another
233+ # method from the random module of the Python Standard
234+ # Library.
226235 #
227236 # Use the Python Standard Library's random module to call the
228237 # random.getrandbits(k) function that is based on the
@@ -233,13 +242,69 @@ def gen_rand_signal_uniform_distributn(type_of_signal=bv_signal, n=16):
233242 # - low value: "0"
234243 #
235244 # @param n - number of discrete values used to represent the
236- # random signal/"process".
237- # Its default value is: 16.
245+ # random bit vector signal/"process".
246+ # Its default value is: 16.
238247 # @return - Nothing.
239248 # O(1) method.
249+ #
250+ # Reference:
251+ # + [KiteStaff2020]
252+ # - Kite staff, "getrandbits", from Kite: The Python Language:
253+ # Kite Docs: random, Kite, San Francisco, CA, no date.
254+ # Available online from Kite: The Python Language:
255+ # Kite Docs: random at: https://kite.com/python/docs/random.getrandbits;
256+ # February 12, 2020 was the last accessed date.
257+ #
258+ # Additional resources:
259+ # + https://pythonhosted.org/bitstring/bitarray.html
260+ # + https://wiki.python.org/moin/BitArrays
261+
240262 @staticmethod
241263 def gen_bit_vector_getrandbits (n = 16 ):
242- return random .getrandbits (n )
264+ # Empty list representation of a random bit vector/signal.
265+ list_of_int_representation_of_bv = []
266+ """
267+ Since the method call random.getrandbits(n) generates
268+ an integer representation of a bit-vector, the
269+ bin() method is needed to map/transform the
270+ integer-representation of a bit-vector into a
271+ binary string representation.
272+
273+ Add one to the input argument of random.getrandbits(),
274+ since it would only generate (n-1) values/digits
275+ otherwise.
276+
277+ References for using bin() to convert integers
278+ into a binary string.
279+ + \cite[From section 'Built-in Functions']{DrakeJr2016b}.
280+ - Available online from Python: Python 3.8.2rc1
281+ documentation: The Python Standard Library:
282+ Built-in Functions at: https://docs.python.org/3/library/functions.html#bin;
283+ February 12, 2020 was the last accessed date.
284+ + \cite{KiteStaff2020}
285+ """
286+ #bin_representation_of_bv = bin(random.getrandbits(n+1))
287+ bin_representation_of_bv = bin (random .getrandbits (n ))
288+ print ("!!! bin_representation_of_bv is:" ,bin_representation_of_bv ,"." )
289+ print ("!!! bin_representation_of_bv[2:] is:" ,bin_representation_of_bv [2 :],"." )
290+ """
291+ Map/transform the integer-representation of a
292+ bit-vector into a binary string representation.
293+ """
294+ list_representation_of_bv = list (bin_representation_of_bv [2 :])
295+ """
296+ For each value/digit/bit in the random bit vector
297+ signal/"process",
298+ """
299+ #for value_in_bv in list_representation_of_bv:
300+ for index_in_bv in range (len (list_representation_of_bv )):
301+ """
302+ Cast it into an integer and add it to the
303+ list representation of the random integer
304+ bits.
305+ """
306+ list_of_int_representation_of_bv .append (int (list_representation_of_bv [index_in_bv ]))
307+ return list_of_int_representation_of_bv
243308
244309
245310
0 commit comments