QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

Not random

May 20 2012 at 9:43 AM
lawgin  (no login)


Response to yes

 

The code below uses your algorithm to pick 1000000 pairs of numbers. The output suggests that with the exception of 25, the higher the number, the more likely it is to be picked.

RANDOMIZE TIMER
DIM t(25) AS LONG
DO

first% = 1 + RND * 23 'picks a # from 1-24
second% = first% + 1 + RND * (24 - first%) 'picks a # between first% + 1 & 25

k = k + 1
IF first% = second% THEN c = c + 1
t(first%) = t(first%) + 1
t(second%) = t(second%) + 1
LOOP WHILE k < 500000

FOR a = 1 TO 25
PRINT a; t(a),
s = s + t(a)
NEXT

PRINT: PRINT
PRINT "Number pairs:"; s
PRINT "Duplicates:"; c


 
 Respond to this message   
Responses

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement