How to Choose random alphabet in sketchware |sketchware pro tutorial
Hello coders
Today I was searching for block to choose random alphabet from a to z. I know that how to choose any random number but not know how to choose random alphabet. Also I searched about it on YouTube, google and stackoverflow but I not get a satisfactory answer.
So I researched about it and then I found two methods for doing this. So in the below article both methods are explained.
Method #1
Method 1 is long method, also loading it is difficult and you have to same work for again and again. In this I put values e.g. if get random = 1 then textview set text A. If get random = 2 then textview set text B.
And really this method not worth. Because if only one line of code is wrong then you find it difficult to fix it.
If you want this method then comment below I'll surely make a tutorial on this method.
Method #2
This method is best method. Even I recommend it to Android developers also. In this method you can do customisation. So let's start making project.
OnCreate event
In oncreate I put a string named "var" to value ABCDEFGHIJKLMNOPQRSTUVWXYZ. You can change it if you want to choose random from anything else.
Variables
A number variable pos
A string variable var
A list string chars
Moreblock
For this project I have made a moreblock you can make the same
or You can download from this link.
On button Click
On button click I added moreblock with value as string var.
Then I used block textview set text "". So that textview will be empty before creating random alphabet (you can use it as you like).
Then I used a repeat block because I want to generate 6 letter random.
You can change it to number of letters you want. Then textview set text " textview get text + get at pick random 0 to length of list string - 1 of list string chars"
For generating only 1 letter
I used textview get text because I want to generate 6 letters. If I want to generate only 1 letter then this was not necessary. If you want to generate only 1 letter then will ve more simple.
Only this code is needed for generating 1 random letter.
For generating small alphabets
In this tutorial I tell method about Capital letters. If you want small letters then change the combination ABCDEFGHIJKLMNOPQRSTUVWXYZ to abcdefghijklmnopqrstuvwxyz . And if you want both Capital and small alphabets then use ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz . Also you can replace numbers or symbols as per your creativity.
Comments