I was trying to turn one of Knuth's random number sampling without replacement algorithms. It seems to be working, but when it comes time to return my prize ... nothing :(
I thought that since I was returning from inside of the named let, that I'd get back my collection of numbers sampled without replacement. ;; algorithm taken from: ;; https://stackoverflow.com/questions/311703/algorithm-for-sampling-without-replacement (define (sample-without-replacement n N) (let loop ([num-seen 0] [num-stored 0] [result '()]) (let ([u (random)]) (display (format "~a\n" result)) (unless (>= num-stored n) (if (>= (* u (- N num-seen)) (- n num-stored)) (loop (add1 num-seen) num-stored result) (loop (add1 num-seen) (add1 num-stored) (cons num-seen result)))) result))) -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CACgrOxLK7mx5svyC34uKm4XRcXVBBvP9hq83M7WhBStNRA%2Bpaw%40mail.gmail.com.

