#include<iostream>
#include<vector>
using namespace std;
int main()
{
	const int TYPE_OF_FISH=4;
	vector<Fish*>FishVec(TYPE_OF_FISH);
	FishVec[0]=new AustralianBass();
	FishVec[1]=new EelTailedCatfish();
	FishVec[2]=new GippslandPerch();
	FishVec[3]=new ShortFinedEel();

cout<<"welcome for fish catching \n";
cout<<"press any to go out \n";
cout<<"keep pressing enter to get catch\n";
int i;
Fish* aFish;
char response;
RandomInt d4(0,TYPE_OF_FISH-1);
for(;;)
{
	cin.get(response);
	if(response!='\n')
		break;
	i=d7.generate();
	aFish=FishVec[i];

	cout<<"caught"<<aFish->getName()
		           <<aFish->getScientificName()
		    <<aFish->getWeight()
	                <<aFish->printMe();
}
for(i=0;i<TYPE_OF_FISH;i++)
delete FishVec[i];
cout<<"have a nice day for catching fish"<<endl;

please help me to catch diffrent type of fish randomly
how can i generate randomly from this function
RandomInt d4(0,TYPE_OF_FISH-1);

Recommended Answers

All 4 Replies

hi,

if you want to draw an int random number rn out of [0.. n-1] you can do that by supplying rn = rand() % n. rand() always produces the same sequence of random numbers. To avoid this, for example in game program, where you need "true" random numbers, you can initialize rand() with srand( time(NULL) ). Depending on the time, now you get various sequences of random numbers. To get an index for the fish array you may assign index = rand () % TYPE_OF_FISH;

C function rand() isn't that an awesome random generator, for example its period is just 32767-1. Much more better is MTRand of MersenneTwister.

krs,
cliff

thanks a lot
i got random number now

hi,

if you want to draw an int random number rn out of [0.. n-1] you can do that by supplying rn = rand() % n. rand() always produces the same sequence of random numbers. To avoid this, for example in game program, where you need "true" random numbers, you can initialize rand() with srand( time(NULL) ). Depending on the time, now you get various sequences of random numbers. To get an index for the fish array you may assign index = rand () % TYPE_OF_FISH;

C function rand() isn't that an awesome random generator, for example its period is just 32767-1. Much more better is MTRand of MersenneTwister.

krs,
cliff

thanks a lot
i got random number now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.