anything
2021-1-3 15:30:02

It does. Here’s ten runs. fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3) fact-example-syntax.rkt> (random-sample (list 1 2 3) 3 #:replacement? #f) '(1 2 3)


badkins
2021-1-3 17:28:11

There does seem to be a bug in random-sample. Running the following repeatedly: (random-sample '(1 2 3 4) 3 #:replacement? #f) gives results where the first element is 1 or 4, never 2 or 3


mflatt
2021-1-3 17:28:30

I think this is the intended behavior of random-sample: “Returns a list of n elements of seq, picked at random, listed in any order.” So, if you pick 3 elements of a sequence that has only 3 elements, the only choice is to get all of them. And since they can be returned in any order, the original order is valid.


badkins
2021-1-3 17:29:35

Ah. Yes, I had a preconceived notion of what to expect.


mflatt
2021-1-3 17:29:37

And the “in any order” part means that if the first element of a 4-element sequence is picked, it’s ok to always report it as the first element of the result.


mflatt
2021-1-3 17:30:56

I’ve never looked at this function before, and I’m still unclear on what #:replacement? is supposed to do. The documentation probably needs to be improved and have examples.


badkins
2021-1-3 17:32:37

Maybe bold the listed in any order part :)


badkins
2021-1-3 17:33:03

With replacement would allow picking the same element more than once.


badkins
2021-1-3 17:33:57

Upon re-reading the doc after your comment, it’s technically accurate, but it wouldn’t hurt to emphasize the fact that the sample is not shuffled.


mflatt
2021-1-3 17:34:25

Yes, I think I see now.Probably the docs could be better than “with replacement means with replacement”, just in case someone is unclear on what “with replacement” means in the first place.


samth
2021-1-3 18:46:45

There was a long discussion of this recently, either on the mailing list or github


rokitna
2021-1-3 21:49:32

Oh yeah, now I remember people talking about how if you want them in a random order, you can shuffle them afterward. Forgot about that.


anything
2021-1-4 00:52:40

How can I match-define ’diamonds and the 7 in '(A (diamonds . 7)). If I change the pair for a list, I can do it with (match-define (list _ (list suit val)) '(A (diamonds 7))) Oops! Just figured it out. I need a cons: (match-define (list _ (cons suit val)) '(A (diamonds . 7))) (First time using match. Thanks!)


anything
2021-1-4 01:46:22

Is there a base library procedure for applying a procedure various times as in (f (f (f x)))?


michaelrauh
2021-1-4 02:01:02

I can’t seem to find exactly what you’re looking for, but I think it should be doable with a fold. Here is an example if I am understanding what you’re asking about correctly:

#lang racket (define (apply-times seed proc times) (for/fold ([result seed]) ([i (range times)]) (proc result))) (define (double number) (* 2 number)) (apply-times 3 double 5) > 96 Alternatively, you can frame the issue as calculating a fixpoint if you expect it to eventually converge. I recently had to do this and used:

(define (converge proc x) (define step (proc x)) (cond [(<= step 0) 0] [else (+ step (converge proc step))])) Do either of those examples make sense or help?


anything
2021-1-4 02:17:39

Your first approach seems to be what I’m doing. But instead of for/fold I’m writing the recursion explicitly. Have a look. (Thanks for looking into it. I should probably use for/fold.) (define (n-rounds n a-game) (cond [(= n 0) a-game] [else (n-rounds (sub1 n) (table-one-round a-game))])) I should abstract table-one-round as a procedure argument.