The way I read it he just wants a string of three characters, each of which is either 0, 1, 2, or 3. So the base, leading zeros, etc. aren't relevant. There a lot of ways to do this in CL, but I'm surprised no one has mentioned DIGIT-CHAR.smithzv wrote:Yeah, I took his example of '000' in the body to mean he wants to deal with strings. Just because number has a specific meaning in CL doesn't mean I might not refer to a number that is contained in a string. Also, the question of how many digits are in a number is kind of ill formed until you decide on a few details regarding how a number is printed. For instance, whether leading zeros should be printed or what base the number should be printed in.Paul Donnelly wrote:According to the post title, a string, and according to the post body, a number.gugamilare wrote:Wait, does "miningold" want a number or a string?
This is pretty clearly homework, so I wouldn't normally give a full answer, but since there have been a couple of pretty complete answers so far here's a simple, but not very elegant solution:
(concatenate 'string (mapcar (lambda (x) (digit-char (random x))) '(4 4 4)))
Or at least I think that is correct- haven't really tested it or thought very hard about it so caveat lector.