RandomString

From Liberty Unleashed Wiki
Jump to: navigation, search
Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events


I've created a new function similar to RandomString, so, here's. This function generates a random string based on two integers ( minlength and maxlength )

Syntax

  1. RandomString( int minlength, int maxlength )

Arguments

  • minlength - An integer which sets the minimum length of the string.
  • maxlength - An integer which sets the maximum length of the string.

Example

  1.  
  2. function Letters ( num ) {
  3.  
  4. switch ( num ) {
  5.  
  6. case 0: return "a";
  7. case 1: return "b";
  8. case 2: return "c";
  9. case 3: return "d";
  10. case 4: return "e";
  11. case 5: return "f";
  12. case 6: return "g";
  13. case 7: return "h";
  14. case 8: return "i";
  15. case 9: return "j";
  16. case 10: return "k";
  17. case 11: return "l";
  18. case 12: return "m";
  19. case 13: return "n";
  20. case 14: return "r";
  21. case 15: return "s";
  22. case 16: return "p";
  23. case 17: return "q";
  24. case 18: return "w";
  25. case 19: return "y";
  26. case 20: return "z";
  27. case 21: return "?";
  28. case 22: return "=";
  29. case 23: return "(";
  30. case 24: return ")";
  31. case 25: return "&";
  32. case 26: return "%";
  33. case 27: return "$";
  34. case 28: return "!";
  35. case 29: return "1";
  36. case 30: return "2";
  37. case 31: return "3";
  38. case 32: return "4";
  39. case 34: return "5";
  40. case 35: return "6";
  41. case 36: return "7";
  42. case 37: return "8";
  43. case 38: return "9";
  44. case 39: return "0";
  45. }
  46. }
  47.  
  48. function Random ( type, min, max ) {
  49.  
  50. switch ( type ) {
  51.  
  52. case 0: return rand ( ) % ( min - max ) + min;
  53. case 1: {
  54.  
  55. return rand ( ) % min;
  56. }
  57. }
  58. }
  59.  
  60. function RandomString ( min, max ) {
  61.  
  62. local string = "";
  63. local i = 0;
  64.  
  65. while ( i < max ) {
  66.  
  67. if ( Random ( 1, 1000, 0 ) <= 700 ) string = string + Letters ( Random ( 0, 0, 38 ) );
  68. if ( Random ( 1, 1000, 0 ) > 700 ) {
  69.  
  70. string = string + Select ( Random ( 0, 0, 20 ) ).toupper ( );
  71. }
  72.  
  73. i ++;
  74. }
  75.  
  76. return string;
  77. }
  78.  

Notes

No notes.

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox