Re: Is there something wrong with random function?
Jean Louis <[email protected]> Thu, 16 Nov 2017 00:02:25 +0300
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Nov 15, 2017 at 09:06:10PM +0000, Don Cohen wrote: > 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") I got it! Thanks. Jean ------------------------------------------------------------------------------ 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