Is there something wrong with random function?
[email protected] (Don Cohen) Wed, 15 Nov 2017 21:06:10 +0000
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
Jean Louis writes: > (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))) What do you think happens when the first result of (random 10) is 0 ? Try (read-from-string "012345") ------------------------------------------------------------------------------ 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