Skip to main content
GameDev.net gamedev.net
🔒 Locked

Random number generation

Started by ill Mar 23, 2013 at 9:48 PM 5 replies 4.2k views
Original Post
ill
ill

//why not use random integer code instead of using the random float code to generate a random integer?!?!
int roll = (int) floor(glm::linearRand(1.0f, 7.0f) + 0.5f);

//why not say someValue = roll - 1
if (roll == 1)
	someValue = 0;
else if (roll == 2)
	someValue = 1;
else if (roll == 3)
	someValue = 2;
else if (roll == 4)
	someValue = 3;
else if (roll == 5)
	someValue = 4;
else if(roll == 6)
	someValue = 5;
else if(roll == 7)
	someValue = 6;
else
	someValue = 0;

The things I have to deal with sometimes...

Paradigm Shifter
Paradigm Shifter



//why not use random integer code instead of using the random float code to generate a random integer?!?!
int roll = (int) floor(glm::linearRand(1.0f, 7.0f) + 0.5f);

//why not say someValue = roll - 1
if (roll == 1)
	someValue = 0;
else if (roll == 2)
	someValue = 1;
else if (roll == 3)
	someValue = 2;
else if (roll == 4)
	someValue = 3;
else if (roll == 5)
	someValue = 4;
else if(roll == 6)
	someValue = 5;
else if(roll == 7)
	someValue = 6;
else;
	someValue = 0;

The things I have to deal with sometimes...

I made a small change which will keep people scratching their heads for a while.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Dragonsoulj
Dragonsoulj


I made a small change which will keep people scratching their heads for a while.

That's just wrong...

Postie
Postie


I made a small change which will keep people scratching their heads for a while.

Subtle. I like it.

[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
Cornstalks
Cornstalks

I just realized this: The distribution in the original code is messed up too (of course, all code is messed up to begin with). Numbers are distributed as:


[1.0f, 2.0f) -> [1.5f, 2.5f) -> 50% 1, 50% 2 // Crap, now 1 occurs only half as much as 2, 3, 4, 5 and 6!
[2.0f, 3.0f) -> [2.5f, 3.5f) -> 50% 2, 50% 3 // Good!
[3.0f, 4.0f) -> [3.5f, 4.5f) -> 50% 3, 50% 4 // Good!
[4.0f, 5.0f) -> [4.5f, 5.5f) -> 50% 4, 50% 5 // Good!
[5.0f, 6.0f) -> [5.5f, 6.5f) -> 50% 5, 50% 6 // Good!
[6.0f, 7.0f) -> [6.5f, 7.5f) -> 50% 6, 50% 7 // Crap, now 7 occurs only half as much as 2, 3, 4, 5 and 6!
[7.0f, 7.0f) -> [7.5f, 7.5f) -> ~0.000001% 7 // Pffft. Lame.

Of course, it's possible this code was specially written for this distribution exactly, and you "fixing" it will rip a whole in the fabric of the universe...

Khatharr
Khatharr

Of course, it's possible this code was specially written for this distribution exactly, and you "fixing" it will rip a whole in the fabric of the universe...

Somehow tricking the CPU into dividing by zero without throwing... Who needs the LHC? We've got doomsday on tap, baby. biggrin.png

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.