Define a function that returns a stream of random numbers

Assignment Help Computer Engineering
Reference no: EM132094081

Please answer this in Python:

There is no limit to the count of random numbers to be generated.

A common method of producing pseudo-random numbers is by means of the following recurrence relation:

R0 = seed value

Ri+1 = (a*Ri + c) % n where Ri denotes the ith pseudo-random number in the stream; a, c, and n are constant integers, and seed value is some initial value provided by the user or chosen automatically by the system.

Define a function that returns a stream of random numbers that uses this linear-congruential formula.

from operator import add, mul, mod

def make_random_stream(seed, a, c, n):

"""The infinite stream of pseudo-random numbers generated by the recurrence r[0] = SEED, r[i+1] = (r[i] * A + C) % N. Your solution must not use any lambdas or def's that we have not supplied in the skeleton.

>>> s = make_random_stream(25, 29, 5, 32)

>>> stream_to_list(s, 10) [25, 26, 23, 0, 5, 22, 3, 28, 17, 18]

>>> s = make_random_stream(17, 299317, 13, 2**20)

>>> stream_to_list(s, 10) [17, 894098, 115783, 383424, 775373, 994174, 941859, 558412, 238793, 718506]

Reference no: EM132094081

Questions Cloud

Working mechanism of ransomware : Potential threats and mitigation tools for ransomware - Overview of Network Security - Analyse and discuss common emerging threats, attacks, mitigation
Cost benefit analysis template : Apply a cost-benefit analysis to consider potential profit and risks to your organization based on the experience of Banner Health System.
Perform an amortized analysis of the running time of n : Suppose that after every K operations, we automatically make a copy of the stack for back-up purposes. (Note the stack may or may not be full at this point.)
Immigration platforms of two organizations : Research and compare the immigration platforms of two organizations: one American political party
Define a function that returns a stream of random numbers : Define a function that returns a stream of random numbers that uses this linear-congruential formula.
What are the purposes of integration testing : What are the purposes of Integration testing and who needs to conduct Integration testing?
Light bulbs should be used to light a warehouse : A plant engineer wishes to know which of two types of light bulbs should be used to light a warehouse.
Research and development department : In the research and development department can you tell on what must i based myself when adjusting the size, performance and MTBF.
What was the most difficult part of locating quality : What was the most difficult part of locating quality sources on your topic in Module 6? What was the most rewarding?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd