Well, I can't help you with the whole ASCII thing, but I do know a thing or two about the rand() First off, you need to include this in the preprocessor:
#include <cstdlib>
This file has the random function.
Then you must make the random var.
Try this:
1 2 3 4 5 6 7 8 9
|
int main()
{
int randNumber = rand();
for (int i = 0; i < 10; i++)
{
cout << i << ") " << randNumber << endl;;
randNumber = rand();
}
}
|
this will give you 10 seemingly random numbers.
To edit the range, we need to use the modulus operator (%):
|
int randNumber = (randomNumber % 6) + 1; // get a number between 1 and 6
|
Any positive number divided by 6 will give a remainder between 0 and 5, and then you move the entire range up one, so instead of 0-5 you have 1-6.
The problem with this is that they are not conpleatly random numbers; the compiler reads from a list of numbers. A way to insure that you will allways get random numbers is to make it read from the place in the list based on what time it is. The following code 'seeds' the random number generator:
|
srand(static_cast<unsigned int>(time(0)));
|
Even I don't completely understand this, but it basically selects a place to read from based on what time it is, like I said.
So, a random number code should look something simular to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0)));
int randNumber = (randomNumber % 6) + 1;
cout << randNumber;
int i;
cin >> i;
}
|
I hope this helps!
Respond if you need anything else