Jump to content

  • Log In with Google      Sign In   
  • Create Account

Random number generation

  • You cannot reply to this topic
6 replies to this topic

#1   Members   -  Reputation: 320

Like
3Likes
Like

Posted 23 March 2013 - 03:48 PM

//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, 23 March 2013 - 03:49 PM.


#2   Crossbones+   -  Reputation: 5832

Like
4Likes
Like

Posted 23 March 2013 - 04:02 PM

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

#3   Crossbones+   -  Reputation: 3125

Like
1Likes
Like

Posted 23 March 2013 - 04:21 PM

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

 

That's just wrong...



#4   Members   -  Reputation: 1424

Like
0Likes
Like

Posted 23 March 2013 - 05:02 PM

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

 

Subtle. I like it.


Currently working on an open world survival RPG - For info check out my Development blog: ByteWrangler

#5   Crossbones+   -  Reputation: 7022

Like
12Likes
Like

Posted 23 March 2013 - 05:19 PM

*
POPULAR

They overcomplicated things. Should've done something simpler:

random_number.png


[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6   Crossbones+   -  Reputation: 7022

Like
3Likes
Like

Posted 24 March 2013 - 08:49 AM

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


[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#7   Crossbones+   -  Reputation: 7007

Like
0Likes
Like

Posted 24 March 2013 - 09:32 PM

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, 24 March 2013 - 09:33 PM.

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.





PARTNERS