random suxx

Hey just wonder if there is a way to type out a random word. i cout my questions and then i cout random numbers, but how do i change the numbers to my words instead?

for example:

int main()

vector<string>word


vector<int> slumpadeIndex;

CRandom rand;

for(int i = 0; i < antal; i++)
{
int index = rand.randomize(0, Gfrågor.size());

slumpadeIndex.push_back(index);

cout << randomIndex[i] << endl;
}

for(int i = 0; i < antal; i++)
{

CGfrågor G = Gfrågor[i];

cout << G.getBetyg() << " :: " << G.getFrågor() << endl;

}




class CRandom
{
public:

int randomize(int min, int max);
void seed();


private:



};

#include "CRandom.h"
#include <time.h>

void CRandom::seed()
{
static bool seeded = false;

if(seeded == false)
{
srand (time(0));
seeded = true;
}
}

int CRandom::randomize(int min, int max)
{
seed();
if( min == max)
{
return min;
}
// slumpar tal
int tal = (rand() % (max-min)) + min;


// returnera slumpat tal
return tal;
}
The easy solution is to have the rand max be within the bounds of an array or vector holding the words.

1
2
3
4
5
6
7
8
9
const char *random_words[] = {"foo", "bar", "boo", "far", "pwn"};
const char *rand_word() { return random_words[rand() % 5]; }

int main()
{
  srand(time(0));
  std::cout << rand_word() << std::endl;
  return 0;
}
Topic archived. No new replies allowed.