Previous: , Up: random utils   [Index]


49.7.4 Specialised string functions

The auxiliary library (vicare crypto randomisations strings) exports bindings specialised to handle strings and randomness sources; it is based on both (vicare crypto randomisations) and (vicare containers strings). Arguments to the following functions follow the same conventions established for (vicare containers strings) and (vicare containers strings low). Interface conventions

Function: random-string-unfold-chars integer-maker number-of-chars

Given the closure integer-maker returning a random integer, build and return a new string of number-of-chars random characters.

As a usage example, the following program will generate random passwords with characters in the range of graphics ASCII codes (warning: for real world applications, use a true random source):

(import (rnrs)
  (vicare randomisations)
  (vicare randomisations strings)
  (vicare char-sets))

(random-string-unfold-chars
  (lambda ()
    (do ((ch (random-integer 127) (random-integer 127)))
        ((char-set-contains? char-set:ascii/graphic
                             (integer->char ch))
         ch)))
  10)
Function: %random-string-shuffle source str start past
Macro: random-string-shuffle S source

Build a new string copying the selected substring, then shuffle it using randomness from the given source. Return the new string.

Function: %random-string-shuffle! source str start past
Macro: random-string-shuffle! S source

Shuffle the selected substring using randomness from the given source. Return the shuffled string itself.

Function: %random-string-sample source str start past
Macro: random-string-sample S source

Return a closure that, when evaluated with no arguments, returns a randomly selected item from the selected substring, using randomness from source.

Function: %random-string-sample-population source len str start past
Macro: random-string-sample-population S len source

Return a closure that, when evaluated with no arguments, returns a string of len items randomly selected from the selected substring of str, using randomness from source.


Previous: , Up: random utils   [Index]