Re: Is there something wrong with random function?
Jean Louis <[email protected]> Thu, 16 Nov 2017 23:01:08 +0300
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
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.
> > I have just modified it little so that I can get 6
> > digits, as I actually just need a string of
> > digits to construct web slugs with strings and
> > avoid having same slugs.
>
> I still don't think I understand your intent.
When there is a page named something like "Blue
Sky of Tanzania" for multiple times in a category
of some website, that title is automatically
converted to a "blue-sky-of-tanzania".
I use random numbers to avoid the duplicate file
names, so I make something like:
012651-blue-sky-of-tanzania.html in case that
blue-sky-of-tanzania already exists in the
database.
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