Write this program using Mips programming language In this p
Solution
The ability to generate random number can be useful in certain kinds of program,particularly in games, statistics modeling programes, and scientific simulations tha need to model random events. Take games for example...without random events monsters would always attack you the same way , youd always find the same teaser, the dungeon layout would never change, etc.... And that would not make for very good game.
So how to generate random numbers? In ral life , we often generate random results by doing things like flipping a coin, rolling a dice, or shuffling a deck of cards these events involve so many physical variables that they become almost impossible to predict or control, and produce results that are for all intents and purposes random.
Consequently, computers are generally incapable of generating random numbers. Instead, they must simulate randomness, which is most most often doing pseudo- random number generators.
Its actually fairly easy to write a PRNG. Heres a short program that generates 100 pseudo-random numbers.
#include < iostream>
Unsigned int PRNG( )
{
// our initial starting seed is 53
23
Static unsigned int seed =5323
// take the current seed and generate a new volume from it
// Due to our use of large constants and overflow, it would be
// very hard for someone to predict what the next number is
// going to be from the previous one.
Seed= (8253729 * seed. + 2396403);
// take the seed and return a value between 0. and 32768;
Returns seed. . 32768;
}
int main( )
{
// print. 100. Random. Numbers
For. (int. count=0; count. < 100; ++count)
{
Std : : cout. << PRNG( ). << \"\\t\";
// if we have printed 5 numbers, start a new row
if (( count +1) % 5 ==0)
Std : : count << \" \ \";
}
}
Generating random numbers in c++
C ( and by extension c++) comes with built in pseudo random number generator. It is implemented as two seperate functions that live in the cstdlib header:
Srand( ) sets the initial seed value to a value that is passed in by caller. Srand( ) should only be called once.
Rand( ) generates the next random number in the sequence. That number will be a pseudo-random integer between 0 and RAND_MAX, a constant in cstdlib that is typically set to 32767.

