Re: Is there something wrong with random function?
Pascal Bourguignon <[email protected]> Fri, 17 Nov 2017 20:18:01 +0100
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
> 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”) -- __Pascal J. Bourguignon__ ------------------------------------------------------------------------------ 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