The Cave of Dragonflies forums

Go Back   The Cave of Dragonflies forums > Websites > Webmaster Help and Discussion

Notices

Reply
 
Thread Tools
  #1  
Old 04-23-2014, 09:41 PM
Nira's Avatar
Nira Nira is offline
you cannot have my pain
 
Join Date: November 1, 2011
Location: Stuttgart, Germany
Age: 18
Posts: 2,677
Pronoun: they
Nira is an unknown quantity at this point
Default First attempts at Java.

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.
__________________
"Listen to the words of a fool. If they cannot make you less foolish, at least let them give you hope. For I, of all people, have changed."
Reply With Quote
  #2  
Old 04-23-2014, 11:38 PM
1. Luftballon 1. Luftballon is offline
Banned
 
Join Date: June 24, 2008
Posts: 3,363
Pronoun: it
1. Luftballon is an unknown quantity at this point
Default Re: First attempts at Java.

Quote:
Originally Posted by Majora View Post
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.
Reply With Quote
Reply

Tags
java

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Pokémon, Pikachu and all other Pokémon characters © Nintendo, Game Freak and Creatures Inc. The Cave of Dragonflies, content, styles, etc. © Butterfree/Dragonfree/antialiasis.
Forum now hosted by Eevee's HQ.