Author Topic: Random strings and numbers generator  (Read 1380 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
Random strings and numbers generator
« on: April 26, 2018, 10:24:36 AM »
Hello

This program generates some random strings and numbers from a define list of characters.
You can permutate or add more characters to  the list of characters to generate more randomness

please test it out and inform me if you can improve on this program and its security. Thanxx

Code: [Select]
' RanStGen.o2bas
'  Random Strings and numbers generator
  $ filename "RanStGen.exe"
       uses rtl64

       uses chaos
' Simple random number generator
 ! GetTickCount lib "kernel32.dll" alias "GetTickCount" () as dword
 ! srand lib "msvcrt.dll" (int seed)
 ! rand lib "msvcrt.dll" () as int
   seed=GetTickCount


  def Trim ltrim(rtrim(%1))





dim as long   RdNumb(100)
dim as string RdWord(100)



'=====================================
SUB NRandomGen()
 ' Generate some random strings and numbers arrays

   DIM Number AS INTEGER, RdWordSize AS INTEGER
   DIM RChars AS STRING
   DIM RDig   AS STRING
   DIM I , J  ,  NumChars  AS INTEGER

   DIM RdWholeDig AS STRING

 

   ' Selection of characters
    NumChars = 73
    RChars = "ABCDEFGHIJK=LMNOPQRSTUVWX)YZ0123456789 abcdefghijklmnopqr stuvwxyz-+$#@!"
   
   ' digits selection
   RDig = "0123456789"

    Number = 100
    RdWordSize = 90

 
    FOR I = 1 TO Number
      RdWord(I) = ""
      RdWholeDig = ""
 
      FOR J = 1 TO RdWordSize
          RdWord(I) = RdWord(I) +           MID(RChars, irnd(1,NumChars) + 1, 1)
          RdWholeDig = RdWholeDig +   MID(RDig, irnd(1,10) + 1, 1)
      NEXT J
      RdNumb(I) = VAL(LEFT(RdWholeDig,5))

    NEXT I


END SUB




'---------------------------------------
'  Main start
   LONG   rn
   string   RandSt , RandNum

   ' Generate some random strings and numbers
     NRandomGen

    RandNum = ""
    RandSt = ""

   FOR rn = 1 TO 100
       RandSt = RandSt + LEFT( RdWord(rn),16) + chr(13,10)
      RandNum = RandNum + TRIM(STR(RdNumb(rn)))  + chr(13,10)
   NEXT rn

   putfile "Random strings.txt" ,  RandSt
   putfile "Random numbers.txt" , RandNum
 
   print  " done "