By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

random names, yeap im bored

P: n/a
/*i think someone should use this to name their baby*/
import java.util.Random;
public class name
{
public static void main(String[] args)
{
String string1;
char char1 = 7;
string1 = " ";
int temp, length;
Random generator = new Random();
length = generator.nextInt(10);
for(int blah = 0;blah <= length;blah++)
{
temp = generator.nextInt(26);
if(temp == 1)
char1 = 65;
if(temp == 2)
char1 = 66;
if(temp == 3)
char1 = 67;
if(temp == 4)
char1 = 68;
if(temp == 5)
char1 = 69;
if(temp == 6)
char1 = 70;
if(temp == 7)
char1 = 71;
if(temp == 8)
char1 = 72;
if(temp == 9)
char1 = 73;
if(temp == 10)
char1 = 74;
if(temp == 11)
char1 = 75;
if(temp == 12)
char1 = 76;
if(temp == 13)
char1 = 77;
if(temp == 14)
char1 = 78;
if(temp == 15)
char1 = 79;
if(temp == 16)
char1 = 80;
if(temp == 17)
char1 = 81;
if(temp == 18)
char1 = 82;
if(temp == 19)
char1 = 83;
if(temp == 20)
char1 = 84;
if(temp == 21)
char1 = 85;
if(temp == 22)
char1 = 86;
if(temp == 23)
char1 = 87;
if(temp == 24)
char1 = 88;
if(temp == 25)
char1 = 89;
if(temp == 26)
char1 = 90;
string1 = string1 + char1;
}
System.out.println(string1);
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"trs1800" <no**@coo.ca> wrote in message
news:RH*****************@fe2.texas.rr.com...
/*i think someone should use this to name their baby*/
import java.util.Random;
public class name
{
public static void main(String[] args)
{
String string1;
char char1 = 7;
string1 = " ";
int temp, length;
Random generator = new Random();
length = generator.nextInt(10);
for(int blah = 0;blah <= length;blah++)
{
temp = generator.nextInt(26);
if(temp == 1)
char1 = 65;
if(temp == 2)
char1 = 66;
if(temp == 3)
char1 = 67;
if(temp == 4)
char1 = 68;
if(temp == 5)
char1 = 69;
if(temp == 6)
char1 = 70;
if(temp == 7)
char1 = 71;
if(temp == 8)
char1 = 72;
if(temp == 9)
char1 = 73;
if(temp == 10)
char1 = 74;
if(temp == 11)
char1 = 75;
if(temp == 12)
char1 = 76;
if(temp == 13)
char1 = 77;
if(temp == 14)
char1 = 78;
if(temp == 15)
char1 = 79;
if(temp == 16)
char1 = 80;
if(temp == 17)
char1 = 81;
if(temp == 18)
char1 = 82;
if(temp == 19)
char1 = 83;
if(temp == 20)
char1 = 84;
if(temp == 21)
char1 = 85;
if(temp == 22)
char1 = 86;
if(temp == 23)
char1 = 87;
if(temp == 24)
char1 = 88;
if(temp == 25)
char1 = 89;
if(temp == 26)
char1 = 90;
string1 = string1 + char1;
}
System.out.println(string1);
}
}


1) Your number, temp, will always be in the range 0-25, not 1-26. Either add
one before you go on, or better yet...

2) Instead of "if (temp == 1) ... if (temp == 2) ... blah blah blah string 1
= string 1 + char1;", how about "string1 = string1 + (temp + 65);"

3) This is more of a password generator. If you really want a name
generator, get a good name list, parse it, and pull names from it randomly.
There's some good ones out there. If you want size, look for a census
website.
Jul 17 '05 #2

P: n/a
"Ryan Stewart" <zz********@gSPAMo.com> wrote in message
news:xs********************@texas.net...
"trs1800" <no**@coo.ca> wrote in message
news:RH*****************@fe2.texas.rr.com...
/*i think someone should use this to name their baby*/
import java.util.Random;
public class name
{
public static void main(String[] args)
{
String string1;
char char1 = 7;
string1 = " ";
int temp, length;
Random generator = new Random();
length = generator.nextInt(10);
for(int blah = 0;blah <= length;blah++)
{
temp = generator.nextInt(26);
if(temp == 1)
char1 = 65;
if(temp == 2)
char1 = 66;
if(temp == 3)
char1 = 67;
if(temp == 4)
char1 = 68;
if(temp == 5)
char1 = 69;
if(temp == 6)
char1 = 70;
if(temp == 7)
char1 = 71;
if(temp == 8)
char1 = 72;
if(temp == 9)
char1 = 73;
if(temp == 10)
char1 = 74;
if(temp == 11)
char1 = 75;
if(temp == 12)
char1 = 76;
if(temp == 13)
char1 = 77;
if(temp == 14)
char1 = 78;
if(temp == 15)
char1 = 79;
if(temp == 16)
char1 = 80;
if(temp == 17)
char1 = 81;
if(temp == 18)
char1 = 82;
if(temp == 19)
char1 = 83;
if(temp == 20)
char1 = 84;
if(temp == 21)
char1 = 85;
if(temp == 22)
char1 = 86;
if(temp == 23)
char1 = 87;
if(temp == 24)
char1 = 88;
if(temp == 25)
char1 = 89;
if(temp == 26)
char1 = 90;
string1 = string1 + char1;
}
System.out.println(string1);
}
}
1) Your number, temp, will always be in the range 0-25, not 1-26. Either

add one before you go on, or better yet...

2) Instead of "if (temp == 1) ... if (temp == 2) ... blah blah blah string 1 = string 1 + char1;", how about "string1 = string1 + (temp + 65);"

3) This is more of a password generator. If you really want a name
generator, get a good name list, parse it, and pull names from it randomly. There's some good ones out there. If you want size, look for a census
website.


Correction on 2): "string1 = string1 + (char) (temp + 65);"
Jul 17 '05 #3

P: n/a
OR:

public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++) s.append((char)(65+Math.rand()*26+(i==0?0:32)));
System.out.println(s.toString());
}
}
Jul 17 '05 #4

P: n/a
S Manohar wrote:
OR:

public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++) s.append((char)(65+Math.rand()*26+(i==0?0:32)));
System.out.println(s.toString());
}
}

ah thanks both of you, i have only known java for about 15 days, im
still learning.
Jul 17 '05 #5

P: n/a
trs1800 <no**@coo.ca> wrote in message news:<nz****************@fe1.texas.rr.com>...
S Manohar wrote:
OR:

public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++) s.append((char)(65+Math.rand()*26+(i==0?0:32)));
System.out.println(s.toString());
}
}

ah thanks both of you, i have only known java for about 15 days, im
still learning.

i tried this code just for giggles and does not compile. i fixed it..
should look like this:
public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++)
s.append((char)(65+Math.random()*26+(i==0?0:32)));
System.out.println(s.toString());
}
}

it's the same code, but the line here:
for(int i=0;i<len;i++)
s.append((char)(65+Math.random()*26+(i==0?0:32)));

needed fixing from the previous post.. there is no Math.rand()
function, so just use Math.random() to get the same affect.
anyway, just wanted to post in case anyone else tried it and didnt
work.

take care --
David
Jul 17 '05 #6

P: n/a

"david" <da****@hotmail.com> wrote in message
news:22**************************@posting.google.c om...
trs1800 <no**@coo.ca> wrote in message

news:<nz****************@fe1.texas.rr.com>...
S Manohar wrote:
OR:

public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++) s.append((char)(65+Math.rand()*26+(i==0?0:32))); System.out.println(s.toString());
}
}

ah thanks both of you, i have only known java for about 15 days, im
still learning.

i tried this code just for giggles and does not compile. i fixed it..
should look like this:
public class name{
public static void main(String[] args){
StringBuffer s = new StringBuffer();
int len=(int)(10*Math.random());
for(int i=0;i<len;i++)
s.append((char)(65+Math.random()*26+(i==0?0:32)));
System.out.println(s.toString());
}
}


I think maybe I can name a pet Spacink, but I am not sure if I would name my
child.
Jul 17 '05 #7

P: n/a
> I think maybe I can name a pet Spacink, but I am not sure if I would name my
child.


Ah yes, pleasing the wife too is the hard thing. So how about this?

class name{
public static void main(String[]z){
String v="aeiou",p="cvccvc"; // or cvvcvc, cvcvcv
StringBuffer s=new StringBuffer();
char t;
for(int i=0;i<p.length();i++)
while((v.indexOf(t=(char)(97+Math.random()*26))>=0 ^ p.charAt(i)=='v')
|| s.append(t)==null);
System.out.println(s.toString());
}
}

PS thanks for the correction on rand[om]
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.