Re: Is there something wrong with random function?
Jean Louis <[email protected]> Fri, 17 Nov 2017 23:23:08 +0300
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Nov 17, 2017 at 08:18:01PM +0100, Pascal Bourguignon wrote: > > > > On 16 Nov 2017, at 21:01, Jean Louis <[email protected]> wrote: > > > > On Thu, Nov 16, 2017 at 06:19:56PM +0000, Don Cohen wrote: > >> 6 decimal digits separately you should just call > >> (random 1000000), and if you want leading zeros, > >> then format the output as "~6,'0,d". Or if you > >> don't need the ones that start with zero you > >> could do (+ 100000 (random 900000)) > > > > (defun random-number (&key (digits 6)) > > (setf *random-state* (make-random-state)) > > (let ((format (format nil "~~~A,'0,d" digits))) > > (format nil format > > (random (read-from-string (make-string digits :initial-element #\1)))))) > > > > Something like that also works for me. Thanks for > > a reminder. > > > (loop for width from 2 to 6 collect (format nil "~V,'0D-~A" width (random (expt 10 width)) "base-name")) > ;; —> ("60-base-name" "592-base-name" "3072-base-name" "52258-base-name" "021090-base-name”) (format nil "~V,'0D-~A" 6 (random (expt 6 6)) "base-name") I understand however, I cannot find ~V in CLHS. Where do I find documentation for it? I found just one reference to it in the file: Issues/iss273_w.htm 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