Commit 49568b72 authored by Sergey Katrevich's avatar Sergey Katrevich
Browse files

Simplify generating name for temporary file - using (make-random-state t) for...

Simplify generating name for temporary file - using (make-random-state t) for independent random numbers generation
parent 070cdceb
......@@ -553,51 +553,9 @@ If a string, repeatedly read and evaluate from it, returning the last values."
;;; Support for call-with-temporary-file
;;; (required for windows sbcl <= 1.3.15 where is problem: https://bugs.launchpad.net/sbcl/+bug/1674437 )
(defun random-mini ()
(let (v1 v2)
(setf v1 (get-internal-real-time))
(sleep (/ 1.0 internal-time-units-per-second 2.0))
(setf v2 (get-internal-real-time))
(- v2 v1)))
#|
;; For discovering quality mini-random numbers
(defun get-incf-variants-frequency (repeat)
(loop repeat repeat
for n = (random-mini)
if (= 0 n) count t into res-0
if (= 1 n) count t into res-1
if (= 2 n) count t into res-2
finally (return `((0 ,res-0) (1 ,res-1) (2 ,res-2)))))
|#
;; Results of checking quality "random-mini" numbers
;(get-incf-variants-frequency 100)
;=> ((0 42) (1 56) (2 1))
;(get-incf-variants-frequency 1000)
;=> ((0 421) (1 576) (2 2))
;(get-incf-variants-frequency 10000)
;=> ((0 4289) (1 5703) (2 5))
(defparameter *asdf-random-state* (make-random-state t))
(defun temp-name-extra-part ()
(format nil "-~36R-~36R" (get-universal-time) (+ (get-internal-real-time) (random-mini))))
#| Checking quality extra-suffix for temporary filenames
(let* ((res (loop repeat 10 collect (temp-name-extra-part)))
(res-cleaned (remove-duplicates res :test #'string=)))
(list res res-cleaned (length res-cleaned)))
=> (("-1P91IWH-5QRXF" "-1P91IWH-5QRXG" "-1P91IWH-5QRXH" "-1P91IWH-5QRXI"
"-1P91IWH-5QRXI" "-1P91IWH-5QRXJ" "-1P91IWH-5QRXK" "-1P91IWH-5QRXK"
"-1P91IWH-5QRXL" "-1P91IWH-5QRXL")
("-1P91IWH-5QRXF" "-1P91IWH-5QRXG" "-1P91IWH-5QRXH" "-1P91IWH-5QRXI"
"-1P91IWH-5QRXJ" "-1P91IWH-5QRXK" "-1P91IWH-5QRXL")
7)
|#
(format nil "-~36R-~36R-~A" (get-universal-time) (get-internal-real-time) (symbol-name (gensym))))
(defparameter *temp-filenames-extra-part-p* t)
(defparameter *max-attempts-create-temp-file* 1000)
;;; end Support for call-with-temporary-file
......@@ -644,8 +602,9 @@ Finally, the file will be deleted, unless the KEEP argument when CALL-FUNCTION'e
:with results = (progn (ensure-directories-exist prefix-pn)
())
:for attempts-count :from 0
:for counter :from (random (expt 36 #-gcl 8 #+gcl 5))
:for pathname = (loop
for counter = (let ((*random-state* *asdf-random-state*))
(random (expt 36 #-gcl 8 #+gcl 5)))
for pathname = (parse-native-namestring
(format nil "~A~36R~@[~A~]~@[~A~]~@[.~A~]"
prefix-nns
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment