Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random Programs

Name: Anonymous 2009-12-08 0:05

You know the saying about monkeys and typewriters? What if one used a random number generator to create a valid binary executable? Sure, most of them would crash, but maybe you'd get something interesting eventually?

Name: Anonymous 2009-12-08 16:56

>>34
I was bored, so here's my implementation

(defun pick-random (sequence)
  (let ((length (length sequence)))
    (elt sequence (random length))))

(defun make-random-list (source times)
  (loop repeat times collect (pick-random source)))

(defconstant +BRAINFUCK-COMMANDS+ '#(< > + - |.| |,| [ ]))

(defun make-random-valid-brainfuck (size)
  (let* ((bf
          (make-random-list +BRAINFUCK-COMMANDS+ size))
         ([-count (count '[ bf))
         (]-count (count '] bf))
         (count-diff (- [-count ]-count)))
    (cond
      ((> count-diff 0)
       (append bf (make-list count-diff :initial-element '])))
      ((< count-diff 0)
       (append (make-list (- count-diff) :initial-element '[) bf))
      (t bf))))

;CL-USER> (mapcar #'princ (make-random-valid-brainfuck 50))
;->>+[<,<.<<,.-.,+[++>.+.,+>..[+[><,>+]>]],<>-->[<<]]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List