Random True False

1. Member
Join Date
Dec 1969
Posts
62

## Random True False

I have been using this code to generate and random true false for sometime now. I just want to make sure that there is not a better way to do it. <BR>here is what I have been using.<BR><BR>Randomize<BR>truefalse = (Rnd() * 100) &#060; Chances &#039;Change is the per % time that I use. So if Chances = 48% the code is.<BR>truefalse = (Rnd() * 100) &#060; 48<BR>This give me 48% of the time true and 52% of the time false.<BR><BR>So is this the best way to do this? Is there a better way?<BR>Thanks for your time.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Seems perfect to me!

After all, <BR> Rnd() * 100<BR>will produce a floating point number that is greater than OR EQUAL to 0.0 and LESS THAN 100.0.<BR><BR>That is<BR> 0.0000000000000 &#060;= number &#060;= 99.999999999999<BR><BR>SO when you ask for <BR> number &#060; 48<BR>you are looking to see if the number is<BR> 0.0000000000000 &#060;= number &#060;= 47.999999999999<BR>and that sure seems perfect to me!<BR><BR>You could, of course, instead do<BR> truefalse = Rnd() &#060; ( chances / 100.0 )<BR>and achieve the same thing.<BR><BR>

3. Member
Join Date
Dec 1969
Posts
62

## RE: Seems perfect to me!

Thanks Bill<BR>It has alway worked for me, But today I was going over picking a random number (50000 - 2) * Rnd + 2 and the random true / false that I have been using poped into my head. lol Since you guys are so darn good and I am never quite sure of my coding. I thought it would be a good idea to run it pass you guys. <BR>Thanks for all the help.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•