• Advertisement
Sign in to follow this  

Random number generation

This topic is 1853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

//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...

Edited by ill

Share this post


Link to post
Share on other sites
Advertisement

//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.

Share this post


Link to post
Share on other sites

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

 

Subtle. I like it.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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

Edited by Khatharr

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement