Write a Python generator called rnd_gen(x0, n) that takes a positive integer seed x0 and an int n and produces the sequence of the first n pseudo-random numbers (if n > 0) or an infinite sequence...


Write a Python generator called rnd_gen(x0, n) that takes a positive integer seed x0 and an int n and<br>produces the sequence of the first n pseudo-random numbers (if n > 0) or an infinite sequence<br>numbers (if n < 0). This generator is defined as a function that uses the yield keyword to output a value,<br>as seen on the Chapter 16 lecture PDF file, on slides 60-70. This generator produces the same number<br>sequence as the RndSeq class from part a). Here is how it can be used in a for loop to print the first 10<br>pseudo-random numbers with seed 1:<br>of<br>>>> [i for i in rnd_gen(1, 10)]<br>[22695478, 2156045615, 2867233980, 71484141, 2911408402, 2613937339, 1153135800, 420428313,<br>1503962414, 4187371143]<br>>>> list(rnd_gen(1, 3))<br>[22695478, 2156045615, 2867233980]<br>>>><br>Add in this file a function called main() that demonstrates both the class and the generator by creating<br>and printing lists with the first 10 random numbers with seed 2.<br>

Extracted text: Write a Python generator called rnd_gen(x0, n) that takes a positive integer seed x0 and an int n and produces the sequence of the first n pseudo-random numbers (if n > 0) or an infinite sequence numbers (if n < 0).="" this="" generator="" is="" defined="" as="" a="" function="" that="" uses="" the="" yield="" keyword="" to="" output="" a="" value,="" as="" seen="" on="" the="" chapter="" 16="" lecture="" pdf="" file,="" on="" slides="" 60-70.="" this="" generator="" produces="" the="" same="" number="" sequence="" as="" the="" rndseq="" class="" from="" part="" a).="" here="" is="" how="" it="" can="" be="" used="" in="" a="" for="" loop="" to="" print="" the="" first="" 10="" pseudo-random="" numbers="" with="" seed="" 1:="" of="">>> [i for i in rnd_gen(1, 10)] [22695478, 2156045615, 2867233980, 71484141, 2911408402, 2613937339, 1153135800, 420428313, 1503962414, 4187371143] >>> list(rnd_gen(1, 3)) [22695478, 2156045615, 2867233980] >>> Add in this file a function called main() that demonstrates both the class and the generator by creating and printing lists with the first 10 random numbers with seed 2.

Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here