424,996 Members | 892 Online 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
7 Replies

 P: n/a "trs1800" 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" wrote in message news:xs********************@texas.net... "trs1800" 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

 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

 P: n/a trs1800 wrote in message news:... 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

 P: n/a "david" wrote in message news:22**************************@posting.google.c om... trs1800 wrote in message news:... 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

 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=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 