Jump to content
Sign in to follow this  
opmo

Opusmodus 1.2.23195

Recommended Posts

Opusmodus 1.2.23195


Final update to the seed system.

 

To add a SEED to your own function and make it work you need to follow few simple rules:

Add keyword SEED into the function arguments:

&key seed

 

Next:

(let (state)
(setf state *init-seed*)
(setf seed (rnd-seed seed))

 

The code above should be placed at the beginning of the function.

Nested functions that use seed need to use a (seed) function and not a seed argument.

The (init-state state) should be placed after the random function. The sequential seed numbers give us greater control if a seed needs to be changed or a new one added. All other init-seeds stay unchanged and in the same sequential position.

 

INIT-SEED test:

 

(progn
  (init-seed 1)
  (rnd-sample 4 '(1 2 3 4))
  (gen-eval 4 '(rnd-sample 4 '(1 2 3 4)) :seed 567)
  (rnd-sample 4 '(1 2 3 4))
  (rnd-sample 4 '(1 2 3 4) :seed 67538)
  (rnd-sample 4 '(1 2 3 4) :seed 345)
  (rnd-sample 4 '(1 2 3 4))
  (rnd-sample 4 '(1 2 3 4))
  (rnd-pick '(1 2 3 4) :seed 9756)
  (rnd-pick '(1 2 3 4))
  (rnd-pick '(1 2 3 4))
  (rnd-pick '(1 2 3 4))
  (init-seed nil)
  )

Result:
? init-seed state: 1
rnd-sample n: 4 seed: 1
gen-eval count: 4 seed: 567
rnd-sample n: 4 seed: 3
rnd-sample n: 4 seed: 67538
rnd-sample n: 4 seed: 345
rnd-sample n: 4 seed: 6
rnd-sample n: 4 seed: 7
rnd-pick seed: 9756
rnd-pick seed: 9
rnd-pick seed: 10
rnd-pick seed: 11
init-seed state: nil

 

 

Function example with embedded RND-SEED function:

(defun rnd-foo (n sequence &key seed)
  (let (state)
    (setf state *init-seed*)
    (setf seed (rnd-seed seed))
    (do-verbose ("rnd-foo seed: ~s" seed)
      (let ((result (loop repeat n
                      collect (rnd-pick sequence :seed (seed)))))
        (init-state state)
        result))))

 

All this you will find in the updated documentation. 

Best wishes,

JP


 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×