# Get random letters and put into a string

**URL:** <https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585>\
**Category:** Coding Questions\
**Created:** [March 16, 2021, 5:03pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585 "2021-03-16T17:03:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![resboy2445](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@resboy2445](https://discourse.processing.org/u/resboy2445)\
**Post date:** [March 16, 2021, 5:03pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/1 "2021-03-16T17:03:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 16, 2021, 5:05pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/2 "2021-03-16T17:05:52Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![resboy2445](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@resboy2445](https://discourse.processing.org/u/resboy2445)\
**Post date:** [March 16, 2021, 5:12pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/3 "2021-03-16T17:12:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 16, 2021, 5:15pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/4 "2021-03-16T17:15:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![resboy2445](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@resboy2445](https://discourse.processing.org/u/resboy2445)\
**Post date:** [March 16, 2021, 5:22pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/5 "2021-03-16T17:22:17Z")

</div>

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.

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

}a

```

---

<div class="post-metadata">

**Author:** ![resboy2445](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@resboy2445](https://discourse.processing.org/u/resboy2445)\
**Post date:** [March 16, 2021, 5:24pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/6 "2021-03-16T17:24:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 16, 2021, 5:28pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/7 "2021-03-16T17:28:51Z")

</div>

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](https://processing.org/reference/charconvert_.html)

---

<div class="post-metadata">

**Author:** ![resboy2445](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@resboy2445](https://discourse.processing.org/u/resboy2445)\
**Post date:** [March 16, 2021, 5:33pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/8 "2021-03-16T17:33:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [March 16, 2021, 5:34pm UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/9 "2021-03-16T17:34:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 25, 2021, 10:14am UTC](https://discourse.processing.org/t/get-random-letters-and-put-into-a-string/28585/10 "2021-03-25T10:14:48Z")

</div>

> [@resboy2445](#):
>
> we are supposed to make a distorted word that will be typed by a user using JOptionPane

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]

```auto
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);
}
//

```
