all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* numerical analysis
@ 2004-07-30  2:52 Edward Casey
  2004-07-30 17:05 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: Edward Casey @ 2004-07-30  2:52 UTC (permalink / raw)


This code fragment produces somewhat pseudo-random powerball numbers:

(progn
(random t)
(setq lis6 nil)
(while (< (length lis6) 5)
     ;; (setq cm (+ (mod (* (nth 1 (current-time))(/ (nth 2
(current-time)) 10000)(random)) 52) 1))
     ;; (random t)
      (setq cm (+ (random 52) 1))
      (if (not (member cm lis6)) (setq lis6 (cons cm lis6)))
)
(setq lis6 (sort lis6 '>))
(random t)
(setq cm (+ (random 41) 1))
(setq lis6 (cons cm lis6))
(reverse lis6)
)

The commented-out lines don't seem to work in a loop. Is there some way I
could mix this up some more to get closer to true randomness? In emacs
lisp is it possible to open an arbitrary file (say a compressed graphic
file of white noise) and to advance the file pointer by 8-bit increments?

Thanks in advance for any help.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: numerical analysis
  2004-07-30  2:52 numerical analysis Edward Casey
@ 2004-07-30 17:05 ` Kevin Rodgers
  2004-07-31  4:31   ` Edward Casey
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Rodgers @ 2004-07-30 17:05 UTC (permalink / raw)


Edward Casey wrote:
 > This code fragment produces somewhat pseudo-random powerball numbers:
 >
 > (progn
 > (random t)
 > (setq lis6 nil)
 > (while (< (length lis6) 5)
 >      ;; (setq cm (+ (mod (* (nth 1 (current-time))(/ (nth 2
 > (current-time)) 10000)(random)) 52) 1))
 >      ;; (random t)
 >       (setq cm (+ (random 52) 1))
 >       (if (not (member cm lis6)) (setq lis6 (cons cm lis6)))
 > )
 > (setq lis6 (sort lis6 '>))
 > (random t)
 > (setq cm (+ (random 41) 1))
 > (setq lis6 (cons cm lis6))
 > (reverse lis6)
 > )
 >
 > The commented-out lines don't seem to work in a loop. Is there some
 > way I could mix this up some more to get closer to true randomness?

Why do you (re)set the random number seed more than once?

In what way does the (setq cm ...) form not work?

 > In emacs lisp is it possible to open an arbitrary file (say a
 > compressed graphic file of white noise) and to advance the file
 > pointer by 8-bit increments?

Use find-file-literally or insert-file-contents-literally, then forward-char.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: numerical analysis
  2004-07-30 17:05 ` Kevin Rodgers
@ 2004-07-31  4:31   ` Edward Casey
  0 siblings, 0 replies; 3+ messages in thread
From: Edward Casey @ 2004-07-31  4:31 UTC (permalink / raw)



"Kevin Rodgers" <ihs_4664@yahoo.com> wrote in message
news:410A7FC6.9000808@yahoo.com...
> Edward Casey wrote:
>  > This code fragment produces somewhat pseudo-random powerball numbers:
>  >
>  > (progn
>  > (random t)
>  > (setq lis6 nil)
>  > (while (< (length lis6) 5)
>  >      ;; (setq cm (+ (mod (* (nth 1 (current-time))(/ (nth 2
>  > (current-time)) 10000)(random)) 52) 1))
>  >      ;; (random t)
>  >       (setq cm (+ (random 52) 1))
>  >       (if (not (member cm lis6)) (setq lis6 (cons cm lis6)))
>  > )
>  > (setq lis6 (sort lis6 '>))
>  > (random t)
>  > (setq cm (+ (random 41) 1))
>  > (setq lis6 (cons cm lis6))
>  > (reverse lis6)
>  > )
>  >
>  > The commented-out lines don't seem to work in a loop. Is there some
>  > way I could mix this up some more to get closer to true randomness?
>
> Why do you (re)set the random number seed more than once?

I just wanted to scramble things up a little more. The interpreter
wouldn't allow it within the loop so I called it afterwards. Apparently it
seeds random with a value determined by a combination of transient
hardware states.

>
> In what way does the (setq cm ...) form not work?

The  (progn form does return a list of 6 pseudo-random numbers but  the
commented ;; (setq cm (+ (mod.... [goes with following line that
wordwrapped] apparently didn't work for the same reason that (random t)
didn't, viz. it interrogated the hardware within a loop.

>
>  > In emacs lisp is it possible to open an arbitrary file (say a
>  > compressed graphic file of white noise) and to advance the file
>  > pointer by 8-bit increments?
>
> Use find-file-literally or insert-file-contents-literally, then
forward-char.

Thanks for that. I am still buried under the avalanche of all this new
stuff to learn.

>
> --
> Kevin Rodgers
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-31  4:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-30  2:52 numerical analysis Edward Casey
2004-07-30 17:05 ` Kevin Rodgers
2004-07-31  4:31   ` Edward Casey

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.