samedi 19 mars 2016

mt19937 random number range - weird output 00A8106E

I'm sorry if this has been asked a thousand times, but I've been searching the internet all day, and I simply can't get this to work. I want to create a little game in c++, and therefore I need a function to return random numbers in a specific range.

Most of the answers I found were similar to this one http://ift.tt/1ZdWZtl, and I think this is the solution I'm looking for.

To test if the function does, what I want it to, I tried outputting the results in several different ways.

At the moment my code looks like this:

#include "stdafx.h"
#include <iostream> 
#include <random>


int zufälligeZahl();

int main()
{
using std::cin;
using std::cout;

cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";
cout << zufälligeZahl << "\n";

return 0;
}

int zufälligeZahl()
{
std::random_device rd;
std::mt19937 zGenerator(rd());
std::uniform_int_distribution<int> uni(1, 13);

int random_integer = uni(zGenerator); 

return random_integer; 
} 

I've tried this in many different ways, but no matter what I do, it doesn't work. Either the output is something like 00A8106E, or I don't get any output at all.

I'm using Visual Studio Community 2015

Thanks in advance for you answers. I'm sorry, if the answer is obvious, but the more I searched, the less obvious it became.




Aucun commentaire:

Enregistrer un commentaire