Re: Is there something wrong with random function?
Pascal Bourguignon <[email protected]> Fri, 17 Nov 2017 23:27:23 +0100
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
> On 17 Nov 2017, at 21:23, Jean Louis <[email protected]> wrote: > > 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 See section 22.3 Formatted Output. http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm In place of a prefix parameter to a directive, V (or v) can be used. In this case, format <http://www.lispworks.com/documentation/HyperSpec/Body/f_format.htm#format> takes an argument from args as a parameter to the directive. The argument should be an integer <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_i.htm#integer> or character <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#character>. If the arg used by a V parameter is nil <http://www.lispworks.com/documentation/HyperSpec/Body/a_nil.htm#nil>, the effect is as if the parameter had been omitted. # can be used in place of a prefix parameter; it represents the number of args remaining to be processed. When used within a recursive format, in the context of ~? or ~{, the # prefix parameter represents the number of format arguments <http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#format_argument> remaining within the recursive call. -- __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