2

I'm batch file programmer but I'm experimenting with Small Basic. I know how to generate random numbers as a variable:

Math.getrandomnumber(number)

but I'm not sure how to generate random letters

Kara
  • 6,115
  • 16
  • 50
  • 57
Tristan
  • 27
  • 6
  • I have zero experience with Small Basic, but you can use Text.GetCharacter(number) to get a letter from an input code. So you could use getrandomnumber to get a number, then use it to get the corresponding character. The input code seems to expect ASCII values. – Tobberoth Feb 28 '14 at 13:42

3 Answers3

3

Here you are! Like Tobberoth said, use text.GetCharacter for this. here is the code:

RandNum = Math.GetRandomNumber(25) + 65 'Get a number between 65 and 90 (See ASCII)
RandText = Text.GetCharacter(RandNum)
TextWindow.WriteLine(RandText)
Zock77
  • 951
  • 8
  • 26
1

I don't really know, but if you are dealing with just a few letters, for example ABC, I would do this:

Code:

number = Math.GetRandomNumber(3)
If number = 1 Then
    letter = A
Elseif number = 2 Then
    letter = B
Elseif number = 3 Then
    letter = C
EndIf

This should help.

Shabby Cat
  • 31
  • 5
1

Just to round out the list of suggestions, you can do random anything using arrays.

hex[0] = "0"
hex[1] = "1"
hex[2] = "2"
...
hex[10] = "A"
hex[11] = "B"
hex[12] = "C"
hex[13] = "D"
hex[14] = "E"
hex[15] = "F"

randomHexDigit = hex[Math.GetRandomNumber(16) - 1]

The above will produce a random hex digit from the array.

codingCat
  • 2,396
  • 4
  • 21
  • 27