Home > analyzePRF > utilities > randomword.m

randomword

PURPOSE ^

function f = randomword(n,mode)

SYNOPSIS ^

function f = randomword(n,mode)

DESCRIPTION ^

 function f = randomword(n,mode)

 <n> is the desired length of the word
 <mode> (optional) is
   0 means choose from capital letters
   1 means choose from capital and lowercase letters and digits
   2 means choose from capital and lowercase letters
   3 means choose from lowercase letters
   default: 0.

 return a random word consisting of <n> characters.

 example:
 randomword(5)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function f = randomword(n,mode)
0002 
0003 % function f = randomword(n,mode)
0004 %
0005 % <n> is the desired length of the word
0006 % <mode> (optional) is
0007 %   0 means choose from capital letters
0008 %   1 means choose from capital and lowercase letters and digits
0009 %   2 means choose from capital and lowercase letters
0010 %   3 means choose from lowercase letters
0011 %   default: 0.
0012 %
0013 % return a random word consisting of <n> characters.
0014 %
0015 % example:
0016 % randomword(5)
0017 
0018 % input
0019 if ~exist('mode','var') || isempty(mode)
0020   mode = 0;
0021 end
0022 
0023 % do it
0024 switch mode
0025 case 0
0026   rng = [64+(1:26)];
0027 case 1
0028   rng = [64+(1:26) 96+(1:26) 47+(1:10)];
0029 case 2
0030   rng = [64+(1:26) 96+(1:26)];
0031 case 3
0032   rng = [96+(1:26)];
0033 end
0034 %f = char(rng(randint(1,n,[1 length(rng)])));
0035 f = char(rng(ceil(rand(1,n)*length(rng))));

Generated on Wed 18-Jun-2014 21:47:41 by m2html © 2005