Category : Recently Uploaded Files
Archive   : HEADZIP.EXE
Filename : ROLLDIC2.CPP
// rolldic2.cpp
// This program investigates the odds for rolling pairs
// of dice by randomly generating such rolls.
//----------------------------------------------------------------------
#include
#include
#include "rand2.h"
int main()
{
int totalRolls;
int i;
int currentRoll;
int rollCount[13]; // Only elements 2..12 will be used
int die1;
int die2;
long initialSeed;
cout << "Specify total number of dice rolls: ";
cin >> totalRolls;
cout << "\nSpecify an initial seed (positive integer): ";
cin >> initialSeed;
RandGen gen(initialSeed);
// ASSERT: Object "gen" created using constructor
for (i = 2; i <= 12; i++) // INV (prior to test):
// All rollCount[2..i-1]==0 && i<=13
rollCount[i] = 0;
for (currentRoll = 1; currentRoll <= totalRolls; currentRoll++) {
// INV (prior to test):
// For 2<=k<=12, rollCount[k] == count of
// all dice rolls totaling k out of the
// first currentRoll-1 rolls
// && currentRoll <= totalRolls+1
die1 = int( gen.NextRand()*6.0 ) + 1;
die2 = int( gen.NextRand()*6.0 ) + 1;
rollCount[die1+die2]++;
}
cout << "\nTotal number of simulated dice rolls: "
<< totalRolls << '\n';
for (i = 2; i <= 12; i++) // INV (prior to test):
// rollCount[2..i-1] have been output
// && i <= 13
cout << " Roll: " << setw(2) << i
<< " Occurrences:" << setw(5) << rollCount[i] << '\n';
return 0;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/