Project 5 Tutorial

Project 5 Tutorial - Pseudorandom number sequences A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Pseudorandom number sequences A pseudorandom number generator is an algorithm that produces a sequence of numbers, each of which is almost independent of the others. The closer "almost" is to "completely", the better the quality of the generated sequence. You can use the library function std::rand to produce a sequence that is good enough for the purpose of Project 5. Every time you call the function, you get the next pseudorandom integer in the sequence. The integers generated are approximately uniformly distributed over the integers 0 to RAND_MAX . ( RAND_MAX is a large integer whose particular value we don't care about.) If you want the integers to be uniformly distributed over the integers from 0 to myLimit-1 (where myLimit is much less than RAND_MAX ), this is good enough for our purposes: #include <cstdlib> // for std::rand int myRand(int myLimit) { return std::rand() % myLimit; } Let's try this out. Here's a test main routine : int main() { for (int k = 0; k < 1000; k++) cout << " " << myRand(10);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Project 5 Tutorial - Pseudorandom number sequences A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online