7 | 7 |
(:import [org.ini4j Ini Config BasicProfileSection]
|
8 | 8 |
[javax.naming.ldap LdapName]
|
9 | 9 |
[java.io StringWriter Reader File])
|
10 | |
(:require [clojure.test]
|
11 | |
[clojure.tools.logging :as log]
|
|
10 |
(:require [clojure.tools.logging :as log]
|
12 | 11 |
[clojure.string :as string]
|
13 | 12 |
[clojure.tools.cli :as cli]
|
14 | 13 |
[clojure.java.io :as io]
|
|
258 | 257 |
(if (empty? selected)
|
259 | 258 |
(last weights-and-values)
|
260 | 259 |
(-> (first selected) second))))
|
|
260 |
|
|
261 |
(def ascii-character-sets
|
|
262 |
(let [concatv (comp vec concat)
|
|
263 |
ALPHA (mapv char (range 65 91))
|
|
264 |
alpha (mapv char (range 97 123))
|
|
265 |
digits (mapv char (range 48 58))
|
|
266 |
symbols (concatv (map char (range 33 48))
|
|
267 |
(map char (range 91 97))
|
|
268 |
(map char (range 123 127)))]
|
|
269 |
{:alpha (concatv alpha ALPHA)
|
|
270 |
:alpha-lower alpha
|
|
271 |
:alpha-upper ALPHA
|
|
272 |
:alpha-digits (concatv alpha ALPHA digits)
|
|
273 |
:alpha-digits-symbols (concatv alpha ALPHA digits symbols)
|
|
274 |
:symbols symbols
|
|
275 |
:digits digits}))
|
|
276 |
|
|
277 |
(defn rand-str
|
|
278 |
"Produces a random string of length n, drawn from the given collection of
|
|
279 |
characters. The following keywords may be used in place of a character
|
|
280 |
collection:
|
|
281 |
:alpha - [a-zA-Z]
|
|
282 |
:alpha-lower - [a-z]
|
|
283 |
:alpha-upper - [A-Z]
|
|
284 |
:alpha-digits - [a-zA-Z0-9]
|
|
285 |
:alpha-digits-symbols - all printable ASCII characters besides space
|
|
286 |
:symbols - all visible, non-alpha-numeric ASCII characters (no space)
|
|
287 |
:digits - [0-9]
|
|
288 |
If no character collection or keyword is provided, :alpha-digits-symbols is
|
|
289 |
used by default."
|
|
290 |
([n] (rand-str :alpha-digits-symbols n))
|
|
291 |
([characters n]
|
|
292 |
(let [char-coll (cond
|
|
293 |
(and (keyword? characters) (contains? ascii-character-sets characters))
|
|
294 |
(get ascii-character-sets characters)
|
|
295 |
|
|
296 |
(keyword? characters)
|
|
297 |
(throw (IllegalArgumentException.
|
|
298 |
(str characters " is not a recognized character collection keyword")))
|
|
299 |
|
|
300 |
:else (vec characters))]
|
|
301 |
(apply str (repeatedly n #(rand-nth char-coll))))))
|
261 | 302 |
|
262 | 303 |
;; ## Collection operations
|
263 | 304 |
|