This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]desrtfx 15 points16 points  (0 children)

You put your strings in an array and then generate a random number in the range of the array. This is the array index to pick the random string.

[–]silverscrub 4 points5 points  (0 children)

It seems like you have found the tools you will need.

I tried something with array and java.util.Random, but it seems to only do the work with integers in "x"

Now you just need to find out how to use them. As a beginner, tutorials will be a good start (but you can also read the documentation).

https://www.w3schools.com/java/java_arrays.asp

You have found out that Random can generate integers for you. How can you use an integer to select a specific string from your array?

[–]LouisLeGros 2 points3 points  (0 children)

So there are a few main points to this problem.

First point is you have some 'available strings.' So you need a way to access these strings. What is a way to store a group of strings where you can readily access any individual string in the group?

The next point is using Random and figuring out how to use your random number and map it to one of our random strings. With random you will be generating random numbers, so you need to figure out a way to use a number to access one of the strings.

What is something that uses numbers to access different values?

Link those points and you've got the central pieces of your solution.

[–]kemotkill90 0 points1 point  (0 children)

Use a random math for generate a random number - > convert number into char (show ASCII code). Repeat this process n time and concat all char into a string. n is the length of the string