Changeset 15559 in project
 Timestamp:
 08/24/09 16:43:08 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

chicken/trunk/extras.scm
r14829 r15559 86 86 ;;; Random numbers: 87 87 88 (condexpand 89 (unix 90 91 (define randomseed) 92 (define randomize) 93 94 (let ((srandom (foreignlambda void "srandom" unsignedinteger))) 95 96 (set! randomseed 97 (lambda (#!optional (seed (currentseconds))) 98 (##sys#checkinteger seed 'randomseed) 99 (srandom seed) ) ) 100 101 (set! randomize 102 (lambda (#!optional (seed (##sys#fudge 2))) 103 (##sys#checkexact seed 'randomize) 104 (srandom seed) ) ) ) 105 106 (define (random n) 107 (##sys#checkinteger n 'random) 108 (if (eq? 0 n) 109 0 110 ((foreignlambda* long ((integer64 n)) "return( random() % ((uint64_t) n) );") n) ) ) ) 111 (else 112 113 (define randomseed 114 (let ((srand (foreignlambda void "srand" unsignedinteger))) 115 (lambda n 116 (let ((t (if (null? n) (currentseconds) (car n)))) 117 (##sys#checkinteger t 'randomseed) 118 (srand t) ) ) ) ) 119 120 (define (randomize . n) 121 (let ((nn (if (null? n) (##sys#fudge 2) (car n)))) 122 (##sys#checkexact nn 'randomize) 123 (##core#inline "C_randomize" nn) ) ) 124 125 (define (random n) 126 (##sys#checkexact n 'random) 127 (if (eq? n 0) 128 0 129 (##core#inline "C_random_fixnum" n) ) ) ) ) 88 (define randomseed 89 (let ((srand (foreignlambda void "srand" unsignedinteger))) 90 (lambda n 91 (let ((t (if (null? n) (currentseconds) (car n)))) 92 (##sys#checkinteger t 'randomseed) 93 (srand t) ) ) ) ) 94 95 (define (randomize . n) 96 (let ((nn (if (null? n) (##sys#fudge 2) (car n)))) 97 (##sys#checkexact nn 'randomize) 98 (##core#inline "C_randomize" nn) ) ) 99 100 (define (random n) 101 (##sys#checkexact n 'random) 102 (if (eq? n 0) 103 0 104 (##core#inline "C_random_fixnum" n) ) ) 130 105 131 106
Note: See TracChangeset
for help on using the changeset viewer.