• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

First attempts at Java.

kyeugh

onion witch
Pronoun
she/her
I created a program in Python that creates a random Pesterchum handle (the format being wordWord) from two dictionaries: one consisting of potential first words in the handle, the second consisting of potential second words in the handle. Just to experiment, I figured I would try to write the same program in Java (moreover, my host recently changed its cPanel and I'm super disoriented with it, so I'm trying to write a program in Java to spare time digging around for files that probably aren't worth digging around for).

However, it seems to me like Java doesn't really like generating random words, and that its specialty lies in numbers. After quite a bit of Google-searching around, I've come up empty. I still have no idea how to do this, since most advice that would seem worthwhile are completely useless to me, seeing as I am a complete novice in Java. The most I've ever done is drawn a picture of spaghetti with this language. That's basically it.

So, to clarify, I want to create a program in Java that selects one random word from both dictionaries (I think they're called arrays in Java?), then smashes them together and gives me the final result. No spaces. Nothing fancy. Just one lower-cased word, followed by an upper-cased word, without anything in between them, like I showed you above.

Any help would be greatly appreciated.
 
I created a program in Python that creates a random Pesterchum handle (the format being wordWord) from two dictionaries: one consisting of potential first words in the handle, the second consisting of potential second words in the handle. Just to experiment, I figured I would try to write the same program in Java (moreover, my host recently changed its cPanel and I'm super disoriented with it, so I'm trying to write a program in Java to spare time digging around for files that probably aren't worth digging around for).

However, it seems to me like Java doesn't really like generating random words, and that its specialty lies in numbers. After quite a bit of Google-searching around, I've come up empty. I still have no idea how to do this, since most advice that would seem worthwhile are completely useless to me, seeing as I am a complete novice in Java. The most I've ever done is drawn a picture of spaghetti with this language. That's basically it.

So, to clarify, I want to create a program in Java that selects one random word from both dictionaries (I think they're called arrays in Java?), then smashes them together and gives me the final result. No spaces. Nothing fancy. Just one lower-cased word, followed by an upper-cased word, without anything in between them, like I showed you above.

Any help would be greatly appreciated.

conceptually, the structure you'd like to select from is not a dictionary, but a set—you don't care about the order of the elements or any values associated with them.[1] an array in this context refers to a collection type which contains a fixed number of element cells determined at allocation time with a defined order and a selection function from an integer less than its length to an element determined by the integer provided.[2]

you'd like to take two sets of words, make one "random" selection from each, and concatenate them.

the implementation may be: your sets of words are arrays of String, and you make your "random" selections by requesting two "random" numbers (from java.util.Random, likely), and then indexing into each of the arrays.

such an implementation looks something like this:

Code:
import java.util.Random;

public class Chum
{
    private static String[] fst = {
        "first",
        "second",
        "third" };

    private static String[] snd = {
        "Ninth",
        "Eighth",
        "Seventh",
        "Sixth",
        "Fifth" };

    public static void main(String[] args) {
        Random rnGen = new Random();

        int fstIx = rnGen.nextInt(fst.length);
        String fstWord = fst[fstIx];

        int sndIx = rnGen.nextInt(snd.length);
        String sndWord = snd[sndIx];

        System.out.println(fstWord + sndWord); } }

disclaimers: this isn't very tested; the code is rather exaggerated; and, uh, my coding conventions are admittedly a bit unusual.[3]

uh if this is not comprehensible, like, ask or something.

[1]: of course, a set of A is isomorphic to a dictionary of A by unit (or void, where bottom values are permitted), which is to say a dictionary where the only information associated with a key is its existence.

[2]: the reason that an array is this way is that arrays can be implemented by allocating a block of memory of fixed size, which can be indexed into by adding the position of the first element to an offset multiplied by the size of each element. this isn't relevant in this context, though, as java doesn't admit pointer arithmetic.

[3]: ... my preferred language is haskell, and it shows. tangentially, everyone should totally give haskell a try! it's, like, mind-opening and eyeblowing or something like that.
 
Back
Top Bottom