Get random letters and put into a string

how do we generate random letters in processing, and store them in a string? do we use something like the random() function and the ascii number? i’m not even sure how to do that.

Hi! welcome!! could you elaborate a bit on what you want to do? do you have an example? how long is the string? did you try anything at all?

Also you tagged p5.js but you mentioned processing - which platform are you using? (because it may be quite different in javascript and java)

hey! the platform i am using is processing with java. it’s actually for a homework, the word is supposed to have a fixed length of 6, the letters should be chosen randomly, and be stored in a string.

cool that gives a better idea. did they give you any hint at the course? do you know how to do it with 1 character to begin with - if so can you post a sketch that prints a random character?

we are supposed to make a distorted word that will be typed by a user using JOptionPane, the word should be distorted. i don’t want to type the full homework because i am not sure if it is part of the community guideline.

int num = (int)random(10);
char word = char(num);
void draw() {
println(word);

}a

i thought it was supposed to be something like that to give you a random number and turn that number to a character, using ascii numbers.

according to the guideline we cannot give a full answer (and I’m too lazy to do so) but you should give the code so others can try it. And I think you already have the clues to start with - the reference gives you a good idea of how to print a character from int
https://processing.org/reference/charconvert_.html

yeah, but when i try the code that i typed i don’t get letters, or any number, i get like a box, with an “x” inside of it.




yes, you mentioned ascii before. and in the reference the number is 65 and prints A - I hope that is enough information!

1 Like

Question:

When the user types in a word Hello and the Sketch distorts the word to olelH

Is that what you mean? Shuffle the letters?

Because that is something else than building a new word from random letters (where you’d use ascii) [second concept]

Here is an Example for Ascii

[the second concept]

String result = ""; 

void setup() {
  size(500, 500);

  for (int y = 0; y < 6; y = y + 1) {
    result += char (int(random (65, 65+24)));
  }

  println(result);
}

void draw() {
  background(100);

  text(result, 100, 100);
}
//