I have a project making calls to random numbers, for example:
I have calls that look like this: (random) to generate numbers between 0 and 1, also calls like this: (random n), to generate numbers within range.
What I want to do is put all the random numbers generated throughout the program in a file.
I have this code:
(require (rename-in racket [random random0]))
(define random-port (open-output-file "random-numbers.rktl" #:exists 'replace))
(define (random x)
(define y (random0 x))
(displayln y random-port)
y)
But this isn't working for just (random), but rather for (random n). Is there anyway to make it work for both?
Secondly, where can I put this code if I have multiple modules using random?
Finally, for some reason, when I write something like this:
(for ([i (in-range 100000)]) (random 10))
The numbers are displayed without a problem in the file,
but when I write this: (random 10), I'll get an empty file.
Any help will be really appreciated. Thank you!
Aucun commentaire:
Enregistrer un commentaire