Project 5 Tutorial

# Project 5 Tutorial - Pseudorandom number sequences A...

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

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);

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/07/2009 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

### 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
Ask a homework question - tutors are online