QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

This works, but it's also biased

April 17 2012 at 7:18 PM
AlGoreIthm  (Login AlGoreIthm)


Response to It works just fine

 


range% = 25

first% = INT(RND * range%) + 1

second% = ((INT(RND * (range% - 1) / 2) + 1) * 2 + ABS(first% / 2 = first% \ 2) + (first% = range%))

What the code for second% does is that it produces a value at half the range maximum, then multiplies it by 2, thus generating an EVEN value. And if the first% value is also EVEN, second% adds 1 to itself, making sure that the values are mismatched ODD & EVEN.

It's biased because the values can't be of the same type - they will always be mismatched ODD & EVEN except if the first value is = range%, the second value will be the same type. (According to limited testing so far).


 
 Respond to this message   
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement