Re: Is there something wrong with random function?
<[email protected]> Thu, 16 Nov 2017 13:16:55 +0000
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <03c9fe5fffd6456e95cccc7b55e5ced0@HE105658.emea1.cds.t-internal.com> |
Jean Louis wrote:
(defun random-number (&key (digits 6))
"Returns the random number with 6 digits by default"
(setf *random-state* (make-random-state))
(let ((fstr (make-array '(0) :element-type 'base-char :fill-pointer 0 :adjustable t)))
(with-output-to-string (s fstr)
(dotimes (ti digits)
(princ (character (write-to-string (random 10))) s)))
(read-from-string fstr)))
Don already found the bug, but nobody commented about style.
This function is overly convoluted. Think again about what you want to achieve.
What you're doing above is
Number -> print -> string -> character -> print -> collecting-stream -> adjustable-string -> number
Ouch. Just go straight to your goal.
Regards,
Jörg
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list