int main()
{
RandomShapes();
system("pause");
return 0;
}
int RandomShapes()
{
int RandNum;
for (int s = 0; s<=6; s++)
{
RandNum = rand() % 3 + 2;
int RandomShape[s] ;
RandomShape[s] = RandNum;
std::cout << s << "\n";
}
return 0;
}
but it gives me numbers in order from 0 - 6
why it isn't random like 3 4 2 1 5 6 0 ?
note that this code will be in window, and include <list> or <vector> don't work not sure what they do, but some of the people gave me examples with them. They do work in text command but not in window.
thx :D
appreciate your time
Here is an example where i use a list to store the numbers 1-100.
The Idea is, that i have a 'pool' from where i just randomly determine which position i erase.
Like this you just have to determine 1-100 first and then 1-99 and then 1-98 and you still keep your randomness how you like to do it.
What kind of storage you use, (if vector, or array or similar) is up to you. The idea is shown below.
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <list>
usingnamespace std;
int main()
{
constint Count = 100;
list<int> pool;
srand(time(NULL));
/* just create all numbers 1 - 100 */
for (int i = 0; i < Count; i++)
pool.push_back(i + 1);
/* now generate 100 random positions from where you get the numbers */
for (int i = 0; i < Count; i++) {
int randPos = rand() % pool.size();
list<int>::iterator it = pool.begin();
advance(it, randPos);
cout << *it << " ";
pool.erase(it);
}
cout << endl;
}
i tried this, and it says list undeclared, i did include list, maybe its because the program is in window not text console based, how do i do in window then?