Advertisement

03.16.2008 at 02:55PM PDT, ID: 23245709
[x]
Attachment Details

Understanding a C++ Line of Code

Asked by WJPS in C++ Programming Language, C Programming Language, C# Programming Language

Tags: C++

Hi,

Im a C Sharp Developer mainly, and am converting some C++ code into C Sharp but have come across a line of code that has totally thrown me and I can work out what is it doing. The line is as follows.

define RANDCHANCE(a) ((((float)rand()) + 0.5)*(1.0/(float)RAND_MAX) <= a)

Now im not totally stupid. I know its creating a random number that is a float. Im guessing RAND_MAX is a C++ system varible, but thats not the main issue. I am confused by the RANDCHANCE(a) and <= a at the end. a is never assigned anywhere in the code.

Any help would be great.

Thanks for you time.

Regards

JamesStart Free Trial
 
 
[+][-]03.16.2008 at 03:00PM PDT, ID: 21138711

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, C Programming Language, C# Programming Language
Tags: C++
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.16.2008 at 03:00PM PDT, ID: 21138717

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.16.2008 at 03:07PM PDT, ID: 21138735

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.16.2008 at 03:12PM PDT, ID: 21138756

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628