Scilab Home Page | Wiki | Bug Tracker | Forge | Mailing List Archives | Scilab Online Help | ATOMS
File : Details
Login with GitLab

strrand()

Generates random characters, words or texts from chosen charsets
(1121 downloads for this version - 1121 downloads for all versions)
Details
Version
1.0
Author
Samuel Gougeon
Maintainer
Samuel Gougeon
Category
License
Supported Scilab Version
5.5
Creation Date
July 28, 2015
Description
            strrand(..) generates random characters, words or texts, according to specified
lengths and characters sets. Some predefined sets are proposed.

strrand() will be useful to test string-processing functions, to generate random
names of files or directories with chosen lengths and charsets, to generate
random AGUC sequences in Genetics, etc.

See below for a full help, description, and examples.

RESULTS of EXAMPLES
-------------------
--> strrand(15)
 ans  =
 4dzfqt5pkxd5p9n   
 
--> strrand([10 3 8 0 15])
 ans  =
!aurh8dp4dy  jqg  odf2afu7    7a2xockdtipgdmp  !
 
-->strrand(30, "AGUC")
 ans  = 
 CACGUCGGUGGUCGAGUAAGAGCCGAGCGU   

--> strrand([6 40], "::hex")
 ans  =
!d90a1c  b26e35848d9146be13cfffb13d467983a31124f0  !
 
--> strrand([6 40], "::Hex")
 ans  =
!F2D5DE  9E28E526FB54BB8C606D5CA7AD38CBFF6A6179DC  !
 
--> strrand([6 40], "+AEIOUY")
 ans  =
!nwqj28  46znErtbhlc56jqs9rY7d1AfhlfIxp7Oyfawqquj  !
 
--> strrand([6 40], "+::xfr")
 ans  =
!iühàä9  éëzcöpl1âar1uvûöèj14êêsjzçùgüéhl911ë3soë  !
 
--> strrand([6 40], "::a:xfr")
 ans  =
!crbrcd  tlkbrplïhcajzryïwogékûôplsjqvnùuppvâckog  !
 
--> strrand([6 40], ",.::#:#rom")
 ans  =
!201529  L.45CMI,9V4.8.04CCL7C.7IM1236.MLC1X05XID  !
 
--> strrand(5:5:15, "::ja")
 ans  =
!むめらほと  ろつゆくふすかにかせ 
うつえみをきむにていはたりしと  !
 
--> strrand([6 40], "aaabbc")
 ans  =
!aababc  babbacaabcabbaabaaaaaababababcacaabaabca  !
 
-->// Checking frequencies:
--> s = strrand(6000, "aaabbc");
--> members(['a' 'b' 'c'], strsplit(s)) / 1000
 ans  =
    2.959    1.993    1.048  

-------------------------------------------------------

-->strrand

 Generates random characters, words or texts

SYNTAX
     strrand                      // display this help
 T = strrand(L)                   // use default charset 'a-zA-Z0-9' charset
 T = strrand(L, charsets)         // use or add given charsets
 T = strrand(L, charsets, newSeed) // process with a flying seed

PARAMETERS
 L: Single number, or vector, matrix.. of positive integers:
    The lengths of random texts to be generated.

 charsets: optional string specifying sets of characters to be used.
    * Default: 'abcdefghijklmnopqrstuvwxyz0123456789' are used.
    * If the first character of charsets is "+", the default charset
      is used, and characters or/and classes of characters specified
      after the "+" are ADDED to the default charset.

    * Individual characters must be specified at the beginning of
      the charsets string.
      If any, classes of characters are specified afterwards.
      The list of classes starts with a ":".
      The code of each class is prefixed with ":".
      Therefore, the name of the first specified class is actually
      prefixed with "::"
      Available classes of characters are:
            :a = "abcdefghijklmnopqrstuvwxyz"
            :A = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            :# = "0123456789"
          :hex = "0123456789abcdef"
          :Hex = "0123456789ABCDEF"
          :#rom= "IVXLCDM"
          :xfr = "àâäçéèêëïôöùûü"
          :xFr = "ÀÂÄÇÉÈÊËÏÔÖÙÛÜ"
           :ru =
"абвгдеёжзийіклмнопрстуфхцчшщъыьѣэюяѳѵ"
           :Ru =
"АБВГДЕЁЖЗИЙІКЛМНОПРСТУФХЦЧШЩЪЫЬѢЭЮЯѲѴ"
          :xRu = "ѕЅѡѠѥѤѫѪѩѨѭѬѯѮѱѰ"
           :ja =
"あいうえおはひふへほかきくけこまみむめもさしすせそ"+..
                
"やゆよたちつてとらりるれろなにぬねのわゐんゑを"

    * Statistical frequencies: The average frequency of a character
      or of characters of a class in the generated texts is
      proportional to the number of times that the character appears
      in the whole set of default or/and specified charsets string.
      For instance, 'abb' will generate texts made only of 'a' and 'b'
      with in average twice more 'b' than 'a'.

 newSeed: boolean. If %T (true), the seed of the random generator is changed
      before processing (it is made pointing to the current millisecond).
      This option can be used if one wants to avoid generating the same
      random texts from startup in a reproducible way. After processing,
      strrand() restores the former seed. Default is %F (false).
      To use newSeed with the default charsets, use charsets = "".

 T : Single or vector or matrix of text. T has the sizes of L.

DESCRIPTION
 strrand(..) generates random characters, words or texts, according
 to specified lengths and characters content. Some predefined sets
 of building characters are proposed. Average frequencies of
 characters in output texts are their respective frequencies in
 the building set (see PARAMETERS above, and EXAMPLES below).

SEE ALSO
 * getmd5   : http://help.scilab.org/docs/5.5.2/en_US/getmd5.html
 * tempname : http://help.scilab.org/docs/5.5.2/en_US/tempname.html

REFERENCE:
  Comments, scoring and bug reports are welcome on
  http://fileexchange.scilab.org/toolboxes/367000#comments

EXAMPLES
 strrand(15)
 strrand([10 3 8 0 15])
 strrand(30, "AGUC")
 strrand([6 40], "::hex")
 strrand([6 40], "::Hex")
 strrand([6 40], "+AEIOUY")
 strrand([6 40], "+::xfr")
 strrand([6 40], "::a:xfr")
 strrand([6 40], ",.::#:#rom")
 strrand(5:5:15, "::ja")
 strrand([6 40], "aaabbc")

// Checking frequencies:
 s = strrand(6000, "aaabbc");
 members(['a' 'b' 'c'], strsplit(s)) / 1000
            
Files (1)
[7.54 kB]
Miscellaneous file
File defining the function strrand()

* MAKE strrand() AVAILABLE in EVERY SESSION: Click here to see HOW TO

* Get help: Enter "strrand" without parameters

News (0)
Comments (0)
Leave a comment
You must register and log in before leaving a comment.
Login with GitLab
Email notifications
Send me email when this toolbox has changes, new files or a new release.
You must register and log in before setting up notifications.