It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Guy W. Lecky-Thompson
Gamasutra
September 17, 1999

Letters to the Editor:
Write a letter
View all letters


Features

 

Contents

Introduction

Predictably Random Numbers

Name Generation Techniques

Generating Random Terrain

Plot Sequencing

Code Listings

Listing 1

Listing 2

Listing 3

Listing 4

Listing 5

Listing 1.cpp

// Pseudo Random Number Generation Example

// (c) 1999 Guy W. Lecky-Thompson
// All Rights Reserved

#include <stdio.h>
void main(void)

{

// Choose two large integers such that
// one is double the other

unsigned long ulGenerator1;
unsigned long ulGenerator2;
ulGenerator1 = 4096;
ulGenerator2 = ulGenerator1 * 2;

// Choose a seed value that is between 1
// and the smaller of the large integers

unsigned long ulSeed = 1024;

// Choose a value Max, that represents the highest number that is to be returned

unsigned long ulMax = 2048;

// Generate a series of 10 numbers

for (int i = 0; i < 10; i++)

{

// For each iteration, Multiply Generator1 by
// the seed, and add Generator2

ulSeed = ulGenerator1 * ulSeed;
ulSeed = ulSeed + ulGenerator2;

// The new seed is remainder of this value
// divided by Max

ulSeed = ulSeed % ulMax;

// Return seed as the random value

printf("Iteration : %d %ld\n",i+1,ulSeed);

}

}


 

Listing 2


join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2003 CMP Media LLC

privacy policy
| terms of service