Hello again! I have been working to sorting this issue out on my own, and I got it solved.
First, I learned more about <random> and found out a way to use it without random_device and instead with the system clock. I have to store every value I generate to a designated name/location, but that came in useful later on:
1 2 3 4 5 6 7
|
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::minstd_rand0 generator (seed);
std::uniform_int_distribution<int> D_RANDOM_VALUE(1,1100); //The distribute value
int RANDOM_VALUE = D_RANDOM_VALUE(generator); //The actual value
|
The arrays refuse to generate random numbers and proved to be the biggest roadblock. So instead of hacking together a big code to work around it, I figured, since I already have all the values stored to specific names, I don't need to bother forcing them into an array, but instead just let the array point to their location. This was a major step to a complete solution:
int *RandomArray[1]{&RANDOM_VALUE};
However, there was one more thing missing. The values were randomly generated the first run, but then again, stayed the same. After a bit of tinkering, I realized that I had to re-generate the base values after every time they were called. In my game I used a specific loop to re-generate every ability again, which is highly pragmatic and performance-heavy, but until it becomes a real issue / I figure out how to do it more practical, it will suffice.
1 2 3 4 5 6 7
|
for (int tttt = 0; tttt < 3; tttt++){
RANDOM_VALUE = D_RANDOM_VALUE(generator);
damage = *RandomArray[0];
cout << "This is the damage: " << damage << "\n" << endl;
cout << "This is the random value: " << RANDOM_VALUE << "\n" << endl;
}
|
And this is how I solved it. The game works perfectly fine, and the random-generator has not failed thus far. Here is the complete testcode that sums the post up:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <time.h>
#include <string>
#include <sstream>
#include <random>
#include <chrono>
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::minstd_rand0 generator (seed);
std::uniform_int_distribution<int> D_RANDOM_VALUE(1,1100); //The distribute value
int RANDOM_VALUE = D_RANDOM_VALUE(generator); //The actual value
int health = 2000;
int damage;
int *RandomArray[1]{&RANDOM_VALUE};
using namespace std;
int main(){
AGAIN: //DEBUG
for (int tttt = 0; tttt < 3; tttt++){
RANDOM_VALUE = D_RANDOM_VALUE(generator);
cout << "this is the loop timer: " << tttt << "\n" << endl;
damage = *RandomArray[0];
health = health - damage;
cout << "This is the damage: " << damage << "\n" << endl;
cout << "This is the random value: " << RANDOM_VALUE << "\n" << endl;
cout << "This is the health: " << health << "\n" << endl;
damage = 0;
health = 2000;
system("pause");
system("cls");
}
goto AGAIN; //DEBUG
}
|
With this, I will mark this thread as solved. Hope this will answer the question for everyone who may look it up in the future. Hello from 2016 by the way!! Wuuuu!