Game Rates , Spawn ,fire ,drop ,etc

The Partridge Family were neither partridges nor a family. Discuss.
egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Game Rates , Spawn ,fire ,drop ,etc

Post by egizz983 » September 19th, 2016, 7:26 am

generating random number between 0-10 i got 9 only 3 times in 200 generation tries . I am not very happy with a result of this :

Code: Select all

std::random_device rnum;
			std::mt19937 rnd(rnum());
			std::normal_distribution<> mlvl(5.0, 2.0);
			if (level < 3) {
				meteorlvl = 1;
			}
			if (level >= 3 && level < 8) {
				if (mlvl(rnd) <= (6.0-(((float)level)/10)*1.5)) {
					meteorlvl = 1;
				}
				else {
					meteorlvl = 2;
				}
			}
i already have tried , cuz i was able to get like 6 in a a row meteors by lvl 2 , i am not sure if its because of a rate or its because of a generated numbers . and i was checking a reference abou uniform_real and int distribution and and if you generating a number between 1-10(or any other) all of the numbers have same chance to be generated . its like

Code: Select all

0-1: *
1-2: ****
2-3: *********
3-4: ***************
4-5: ******************
5-6: *******************
6-7: ***************
7-8: ********
8-9: ****
9-10: *
shouldn't i use just int or real distribution instead ?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Game Rates , Spawn ,fire ,drop ,etc

Post by albinopapa » September 19th, 2016, 6:36 pm

You could try it and see if it gives you the results you are after.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Lorth
Posts: 139
Joined: July 19th, 2012, 4:12 pm

Re: Game Rates , Spawn ,fire ,drop ,etc

Post by Lorth » September 20th, 2016, 8:19 am

I have created this "chance" function in a game i am working on. dunno if it might be useful for you.

i created this Before chili introduced the other way to use a random funcktion.

Code: Select all

bool Chances(float procent) { 
	float x = procent / 100;
	int random = (1 / x);
	
	if (rand() % random == 0)
		return true;
	return false; }
example how this works....

Code: Select all

bool returnTrue = Chances(25.0f);
it returns an true or false, depending on what percent value that is inputted.... let's say you want 25% to return true, than you input 25 in the function. and the function will use rand() and return either true or false with a 25% chance to return true....

remember to set srand(time(NULL)); in the code Before using the funciton

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Game Rates , Spawn ,fire ,drop ,etc

Post by egizz983 » September 21st, 2016, 8:05 am

This looks nice for a drop rate , i will use this in a future for sure ,that seems to be nice function i change a bit but result should be same

Code: Select all

bool Game::Chance(float p)
{
	float x = p / 100;
	int random = (1 / x);
	std::random_device rnum;
	std::mt19937 rnd(rnum());
	std::uniform_int_distribution<int> r(0, (random-1));
	if (r(rnd) == 0) {
		return true;
	}
	else {
		return false;
	}
}
i changed just because as chili said by using a rand() some numbers have higher chance to by generated and with uniform_int_distribution all numbers have same chance

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: Game Rates , Spawn ,fire ,drop ,etc

Post by egizz983 » September 21st, 2016, 8:45 am

btw there is a bug in this code , example take 60 or75 and you will get 100% chance any way
60/100 = 0.6
1/0.6 = 1.666 = 1
std::uniform_int_distribution<int> r(0, (random-1));
0-(1-1) = 0
its works with 25,50or 100% but others will give you wrong chance
i made this like this but not sure if i still get accurate results :

Code: Select all

bool Game::Chance(int p)
{
	std::random_device rnum;
	std::mt19937 rnd(rnum());
	std::uniform_int_distribution<int> r(1, 100);
	if (r(rnd) <= p) {
		return true;
	}
	else {
		return false;
	}
}

Post Reply