Random 4 Char Generator Generates 3 Numbers Instead?

Jul 10, 2014

I'm trying to make the basis of a complex (pseudo)random password generator, but instead of 4 chars it is printing a 3 digit number.

public class PasswordGen {
public static void main (String[] args) {
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
int w = (int) ((Math.random() * 25 +1)); // pick a letter of the alphabet

[Code] ....

View Replies


ADVERTISEMENT

Random Generator And 2D Arrays?

Sep 21, 2014

So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?

package Grade12;
 import java.util.Random;
 public class Ghost {
 public static void main(String[] args) {
 Random generator = new Random();
 int gameboard [][] = new int [8][8];
int randomx, randomy, counter = 0, sum = 0; 
for(int row = 0; row < 8; row++){
for(int col = 0; col < 8; col++){ 
(gameboard[row][col]) = 0;
 }

[code]...

View Replies View Related

Random Card Generator

Mar 16, 2015

I've been trying to get a card generator working, but hells bells nothing is easy in java (unless you already the correct answer) trying to figure out the correct way to apply a method you don't understand is like being asked for the German word for banana in Spanish class.

import java.util.Random;
import java.util.Scanner;
class jacktest
{
public static void main ( String[] args ) {
Random r = new Random();

[code]....

my next step might be using object (hammer >=computer)=watch telly instead.

View Replies View Related

Random File Name Generator

Nov 30, 2014

I am splitting a zip file and want to name each fragment with a random name. I want to use java coding for generating this random file name.

View Replies View Related

Random Number Generator Then Summing

Aug 29, 2014

I am brand new to programming and java. I decided I wanted to learn programming so now I'm in a class. I am into my second week and my assignment is to generate 100, 3 digit numbers then add them together. I understand how vast java is, but as of right now we have only studied if/else/switch statements, I was able to get the 100, 3 digit numbers generated, but I cannot add then together.

import java.util.Random;
import java.util.Math;
public class ThreeDigitGenerator {
public static void main(String[] args) {
int sum = 0;

[Code] ....

View Replies View Related

Random Number Generator Error

Dec 1, 2014

I am new at coding and I can't seem to figure out why my random number generator (numGen) won't let me compile. this is the game class to a game i'm making called Bagels. its very similar to the game mastermind in the sense that you have to try to guess a three digit number and the computer will return feedback giving you clues that will guess the number.

import java.util.*;
import java.io.*; 
public class BaglesGame {
public static numGen() {
Random Rainbow = new Random ();
firstDigit = "" + Rainbow.nexInt(10);
 
[Code] .....

View Replies View Related

Creating Random Password Generator?

May 8, 2014

Keeping the passwords at 7 charactersHiding the "[object HTMLInputElement]" next to the passwordsMaking the "Clear" button work to clear the forum

<!DOCTYPE html>
<!-- passwordgenerator.html -->
<html lang="en">

[Code]....

View Replies View Related

Random Bingo Card Generator

May 26, 2014

I'm trying to create a program that will be able to generate random Bingo cards. This is what I have so far.

Java Code:

import java.util.Random;
public class BingoCard
{
private int[][] card;

public BingoCard(Random random)
{
card = new int[5][5];
for (int c = 0; c < 5; c++)

[code]...

The problem with this program is that even with the checkForDuplicateValues method, which checks for duplicate values of a column and replaces the values, it still prints out bingo cards with duplicate values!

View Replies View Related

Program Is A Random String Generator

Sep 11, 2014

The program is a Random String Generator; it takes user input (type of string, and length), and then generates a string with their requested method. Its extremly simplistic, but had some interesting coding challenges considering I only just did 'Hello World' a few days back xP I actually already have quite a few additions and modifications I want to make to it, but wanted to get a bit of feedback on it otherwise.

The Main Class, RandomStringGenerator.java:URL...
InputHandler.java:URL....
RandomGenerator.java: URL....

View Replies View Related

Random Phone Number Generator

May 13, 2011

I am trying to make a phone number generator. I get the following error though when trying to compile.

my post

C:JAVA_PROGRAMMING_CODEcode1RandomPhoneNum>javac RandomPhoneNum.java
RandomPhoneNum.java:23: cannot find symbol
symbol : method toOctalString(int)
location: class RandomPhoneNum
strippedNum = toOctalString(num1);
^
1 error

Here is the code so far

import java.util.Random;
public class RandomPhoneNum
{
public static void main(String[] args)
{
System.out.println("This app prints out a random phone number.");

[Code] ....

Also, how did you people know about octal base numbers? I would never have known that. What I can do to improve my math ability?

View Replies View Related

Random Number Generator And Local Variables

Jul 31, 2014

Basically this code is supposed to create an int array of 50 elements, then pull the elements listed in positions 1-6 to make a lottery draw.

Problem is it gets down to that last "For" statement and then says "duplicate local variable i." If I attempt to separate it from the previous for loop with curly braces, then it gets mad and says it doesn't know what "local variable i" even IS. So I tried changing it to "j" in the last statement and it couldn't recognise that either. I feel like I need to change the variable name in that second for loop but I'm not sure how to make it understand that the second variable is going to be outputting the values from the first variable.

public class Lottery {
public static void main(String[] args) {
// TODO Auto-generated method stub
int []nums = new int [50];
for (int i = 1; i <50; i ++) {nums[i] = i;}

[Code] ....

View Replies View Related

Random Generator Method Is Not Giving Correct Average?

Aug 4, 2014

Create an array that will store 7 temperatures.

Populate the array with 7 random temperatures from 1 to 100 degrees. (hint use a for loop and a Random number Generator)After the temperatures are in the array, calculate the average of the temperatures in the array.

Print out the average.Print out each temperature in a statement comparing it to the average such as:

The average temperature is 48.94

Temperature 1 is 5.0 and is below average.

Temperature 2 is 67.8 and is above average.

import java.util.Random; 
public class ArrayOfTemperatures
{
public static void main(String[] args) {
// Declare an array
int[] randomtemps = new int[7];
temps[0] = 45;

[code]....

View Replies View Related

Random Number Generator To Pick Index From Array?

Oct 31, 2014

Im creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word. I cannot figure out the syntax for the life of me.

View Replies View Related

How To Write Random Number Generator That Will Not Contain Any Repeat Value In A Range

Apr 24, 2015

I am trying to write a Random Number Generator that will not contain any repeat value in a given range

something this I have try so far

import java.util.Random;
/**
* This class is used to generate a
* Range of Random Number in a range from int a to int b
*/
public class RandomNumberGenerator {
public static void main(String[] args) {
int[] arr=randomNummbers(1, 20);
for(int j=0;j<arr.length;j++){

[Code]...

although this code generate random numbers but some values are also getting duplicate.So how to write a program for random number that will not repeat any integer in range?

View Replies View Related

Random Number Generator To Pick Index From Array

Oct 31, 2014

I am creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word.

View Replies View Related

Comparing Array Or Int To 4 Digit Number From Random Generator?

Apr 4, 2015

How do I compare an array (or maybe int?) (example: 3572) to a 4digit number from random generator? how many of the four digit match the generated numbers.

View Replies View Related

Quiz Game Program - Random Number Generator

Nov 18, 2014

I've run into some problems with my Quiz-game program. What I basicly want it to do is generate a random number that is tied to the other windows I have for the program (I want a new random question to be generated once I have guessed on the first one). I've read about a few different ways to approach this but everything I get is a pure number generator.

I imported

import java.util.Random;

into my program but I don't know where to go from there.

View Replies View Related

Random Phone Number Generator - Include Dashes In The Output

Apr 11, 2011

I've been working on a personal project again in Unit 3 of my text book and this time they want me to make a random phone number generator. Here's the actual directions:

"Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX.

Include the dashes in the output.

Do not let the first three digits contain an 8 or 9 (but don't be more restrictive than that), and make sure that the second set of three digits is not greater than 742.

Think through the easiest way to construct the phone number. Each digit does not have to be determined separately."

With this assignment I came across 2 problems:

1. What I tried was that since the first 3 numbers have to be a random number with no 8's or 9's I tried doing this algorithm:

int first0, first1, first2, second, third, random0;
first0 = generator.nextInt (999);
random0 = generator.nextInt (8);
first1 = first0.replace('8', random0);
first2 = first1.replace('9' random0);

The problem is that Java won't allow me to generate random numbers this way. Are there any easier ways of generating numbers that doesn't contain specific number (such as 8 or 9 in this case?)

2. I was thinking about this throughout the whole project and what if I generate a number such as 27 (less than 3 or 4 digit number) rather than 3 or 4 digit numbers? How would it show 0027 or 027 instead of 27 for the phone numbers?

import java.util.Random;
public class pp0303 {
public static void main (String[] args){
Random generator = new Random();
int first0, first1, first2, second, third, random0;

[Code] ....

RESULTS:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot invoke replace(char, int) on the primitive type int
Cannot invoke replace(char) on the primitive type int
Syntax error on token "random0", delete this token
at pp0303.main(pp0303.java:15)

View Replies View Related

Unable To Make Gradebook That Uses Random Number Generator To Give Score

Nov 7, 2014

I`m trying to make a gradebook that uses random number generator to give the score, I also need to implement student numbers and sort everything with a total at the bottom. But I cant figure out how the bubblesorting works. This is my code so far:

package karakterbok;
import static java.lang.Math;
import java.util.Random;
public class Karakterbok {
public static void main(String[] args) {
Random karakterer = new Random();
Random studid = new Random ();

[Code]...

how to sort this using bubblesort?

View Replies View Related

Images Of Cards - Shuffle Deck With Random Number Generator And Display First 10

Aug 18, 2014

So I'm trying to make an applet that displays images of cards. The applet has a deck of 52 playing card images. It should shuffle the deck with a random number generator and display the first 10 cards of the shuffled deck.

With this code I have about 100 errors and I'm not sure what I'm doing wrong: I know I have to use arrays in order to ultimately display the images, but do I have to create Image objects for the Image [] cards array? I am getting many "class, interface, enum expected" errors as well as others.

import java.util.Random;
import java.awt.Image;
import java.applet.Applet;
import java.awt.Graphics;
public class unit12 extends Applet
{

[Code] .....

View Replies View Related

How To Sort Random Char Array Using Lambda Expression In Order

Dec 7, 2014

I have an array that I filled with 30 random characters, but now I am trying to sort them in ascending order and the descending order using lambda expressions.

public class RandomCharacters {
public static void main(String args[]){
Random r =new Random();
char myarray[] = new char [30];
for (int i = 0 ; i < 30; i++)

[Code] ......

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m

y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.

public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];

[Code] ....

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

How To Create Simple Random Number Generator For Number Between 1 -10

May 18, 2015

I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.

View Replies View Related

For Loop With Random Numbers?

Jul 5, 2014

Assume that vehicles are going through a two-way traffic intersection. There are three types of vehicles: car, motor bikes and trucks. Generate a series of 10 random integers, between 1 and 3,inclusive.The numbers represent the type of vehicle as stated below:

NumberVehicle Category
1Car
2Motor bikes
3Trucks

Write a program, using a for loop, to count how many vehicles going through the traffic intersection are cars, motor bikes and trucks. Then, the program should print out the numbers for each vehicle category. There is no user input for this program. How do i do it so they will add up the sum of each vehicle?

The answer should be something like

Number of cars = X
Number of motor bikes = Y
Number of Trucks = Z

but i'm getting

Total number of vehicle:

cars
motorbikes
motorbikes
cars
Trucks
Trucks
motorbikes
motorbikes
Trucks
cars
public static void main(String[] args) {

[code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved