How to get random letter between two letters

Hello everyone!

I have cool random script that show random number between specific numbers (for example 1 and 100) here is demo:

I want to make the same for alphabet letters! How could i do this? Any help?

@fumeeptc. You could try someting like this:

function randomLetter() {
  var letter = "";
  var choice = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  letter += choice.charAt(Math.floor(Math.random() * choice.length));
  return letter;

If you would like multiple letters you could add:

for (var i = 0; i < 5; i++) // or whatever number you want

just before the letter +=

@donboe Thanks! But how does this interacts with user input lets say input one : b input two: g ?

const low = inputFrom.charCodeAt(0);
const high = inputUntil.charCodeAt(0);

const num = // get random number between low and high

const randomChar = String.fromCharCode(num);

This works by taking the letters, mapping them to their ASCII codes, taking a random number between their ASCII codes, which also returns an ASCII code, and then convert that ASCII code to a string again.

In case you don’t know the ASCII table, see here:

1 Like

Hi there fumeeptc,

if you want an example that resembles your “fiddly thingy”
in more ways than seventeen, check out the attachment. :biggrin: (2.1 KB)

And if you don’t, well that’s :ok: too. :rofl:



Looks really good! Thanks allot! I wouldnt be able to make it that way. …

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.