Generating Random Number Between 1-1000
Oct 31, 2013
I am very new to programming. This is for a college assignment. It says in the brief of the assignment that we will need to convert Math.random to output a random number between 1-1000. How can I do this?
View Replies
ADVERTISEMENT
Nov 3, 2014
I have been set this task, which is supposed to make me code using string arrays. The idea is to generate random sentences.This is what i have been able to do so far :
package usingarraysagain;
public class sentences {
public static void main (String[] args){
String[] NOUNS = { "lizards",
"Nikola Tesla",
[code]....
View Replies
View Related
Jan 13, 2014
I've been trying to find the easiest way to write to generate a number which is between intervals of a arbitrary min and a max value.I've been searching for this but I don't find this particular thing.I've found that this combination works:
Java Code: int guess = rand.nextInt(max - (min - 1)) + min; mh_sh_highlight_all('java');
But I wonder, is this really the easiest way of writing it?
View Replies
View Related
Aug 21, 2014
I am working on a bingo project and created random numbers between 1 and 75 to generate. I have it set up that it shows the number in a text box and changes the color on the board if the number is called. When I test the program, some numbers are highlighted in addition to the number called. I believe this is because extra numbers are being chosen, but not being noted in the text box. Below is my code for the unique random numbers.
int CallNo;
String CallerTxt = new String();
public void CallNum() {
Random RandCall = new Random();
//Generate Caller Random Number
CallNo = RandCall.nextInt(75)+1;
[Code] ....
View Replies
View Related
Dec 14, 2014
For part of my program, I am trying to ask the user for input on generating a number of random characters. I have already done this with integers and doubles, how would I do this for characters using ASCII values? Would I use the same format as I did for generating integers (Shown in code)?
import java.util.Random;
import java.util.Scanner;
public class NewNumberCharacter {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
Nov 9, 2014
I don't want to use an array. I do not know of a function built into Java to allow me to do this.
View Replies
View Related
Dec 8, 2014
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?");
}
}
}
View Replies
View Related
Dec 8, 2014
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road.
If you choose to cross, the outcomes for 0-2 are "You crossed safely."
For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street."
For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working,
import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "
Do you wish to cross the road?");
}
}
}
View Replies
View Related
Apr 18, 2014
I am trying to generate a double number from the range [-1,2]
so what i did is this
xs[i]= Math.random() *(2-(-1))+(-1);
I did that as a loop to generate multiple numbers and i got this result:
initial x values 2.17 2.66 3.04 2.81 1.83 2.66 3.67 2.81 1.04 3.1 3 1.23 1.44 3.5 3.84 3.03 1.7 2.79 4 1.43
see some numbers are out of range! and i don't know why aren't there any minus numbers...
View Replies
View Related
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
Feb 1, 2015
the program basically has a random number generating, and I want to ask the user to try to guess the number, and keep guessing until the number is right. In addition to this, I need to put in extra conditions for too high or too low by 10. So for example, if they user guesses a number and its off by more than 10, then it prints that they guessed too high, and if its below 10 they guessed too low.
import java.util.*;
public class RandomNum
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
[code].....
Modify the program to keep the user trying to guess the number till he/she gets it right, and stop once you guess the right number.Too high, high, too low, too low( If it's off by more than 10 = way too high, if its less than 10, way too low)
View Replies
View Related
Sep 13, 2014
I'm trying to produce a random number between 1 and 54 . I think this is correct
int i= (int)(Math.random()*54)+1;
View Replies
View Related
Jan 16, 2015
How would I get java to generate a random number from 0-2? all I've been able to find on random numbers is math.random which gives you from .0 to .10. you can multiply this by 10 to get 1-10 or by 100 to get 1-100 but how to make it so java will simply let me tell it the rand of numbers I want or get a random number in a range that is not a multiple of 10. and I can't seem to find anything about it anywhere.
View Replies
View Related
Sep 25, 2014
I'm trying to use a setter method to pick a random integer to be the MPG for a car. However, I'm having major issues in my driver when trying to use that random number in an instance. I'm not finished with the driver yet because I keep getting "cannot find symbol errors"
import java.util.Random;
public class Car {
private String make;
private String model;
private int year;
private int mpg;
private int odometer;
Random generator = new Random();
[code]...
View Replies
View Related
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
Sep 8, 2014
I am wanting this program to prompt the user to enter a maximum value and a minimum value and the program should in theory generate a random number for the output. Here is my logic:
int maxRange1;
int minRange1;
static int range;
static Random gen;
Then in my mail argument:
gen = new Random();
Scanner input = new Scanner(System.in);
System.out.print("Enter the maximum number: ");
int maxRange1 = input.nextInt();
[Code] ....
I am able to return both the user prompts and get the inputted answer to appear but I am not getting a response for the prompt "The random number is: ".
View Replies
View Related
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
Dec 7, 2014
The problem you have is that it doesn't produce a 4x4 array. For that you need more nested for loops.This is what I have tried so far:
import java.util.Scanner;
import java.util.Random;
public class challenged2e
{
static Scanner console = new Scanner(System.in);
public static int i=0;
public static void main (String args[])
[code]...
I get 21 errors and they all have to do with i and j.
View Replies
View Related
Jun 3, 2014
I am trying to build a Jpanel that when you click the button it generates a random number between one and 100 and then display that number on the screen. It is supposed to start with a label that says Press the button to generate a random number between 1 and 100 and then when you press the button it changes the label to the random number generated. Everything has worked so far except the fact that it will not display the random number generated. It shows the button and the original string but it does't change it to the random number. Here is my code
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class RandomNumberPanel extends JPanel {
private JButton RandomNumber;
private JLabel label;
[Code] ....
View Replies
View Related
Jan 23, 2014
I having a bit of trouble understanding how this works
Math.random();
I know its going to spit out a number between 0 and 1 but I dont know why its in that range if there are no numbers there.
The second part I'm having trouble understanding is how to adjust it for example make it between 1 and 100.
View Replies
View Related
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
Jan 23, 2014
I created the a Time class, a Random number class, and Node class. The thing is when i run the Node class its suppose to spit out a random number and tell me the time it spit it out in nano time. The thing is i cant get the nano time to appear at the time the number was generated. This is my assignment
1) A “MyNum” class that will generate a random integer number from 1 to 200.
2) A “Time” class that will return the system time with sufficient resolution to show the time between insertions. I suggest System.nanoTime().
3) A “Node” class that will encapsulate the integer number and the Time it was generated.
4) And a “Storage class” class that will contain the all the SORTED Nodes using an insertion sort.
a. This class should have a “add” method to add in each node.
b. And method(s) so the driver class may display the sorted list of nodes
5) The “main” or driver class.
But what i want for now is to get the node class to run for now. This is the code so far:
public class Time {
public static long time()
{
return System.nanoTime();
}
}
The Number class
import java.util.Random;
public class MyNum {
static Random number = new Random();
[Code] .....
View Replies
View Related
Apr 12, 2011
how to code the generated a random number from 100 to 150 inclusive for an applet
View Replies
View Related
Oct 26, 2011
I'm trying to write a method that will print a string of a random number of X's (from 5 to 20) on a line, then another number of X's on the next line, etc. until the random number = 16.
I have to use while loops and probably fencepost algorithms. I'm confused with how to print the number of x's the random number of times over and over.
Right now, I'm pretty sure my for loop is wrong or unnecessary.
So far, this is my code:
public static void randomX() {
int x = 0;
while (x != 16) {
x = (int)(Math.random()*20) + 5;
for (int i = 0; i <= x; i++);
{
System.out.print("x");
}
}
}
View Replies
View Related
Jun 16, 2014
Write I program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.
public class NumberGuess
{
public static void main(String[] args) {
// Create a Random object.
final static Random rand = new Random();
// max number is the upward bound number
final int MAXNUMBER = 10;
/**
* Method should return a random number within the upward bound MAX_NUMBER.
[code]....
I get compiler error message
NumberGuess.java:25: error: ';' expected
int getRandomNumber ();
^
NumberGuess.java:63: error: reached end of file while parsing
System.out.println("You got it right in " + numberOfGuesses + " guesses.");
^
How do I fix this?
View Replies
View Related
Apr 1, 2014
Trying to generate random integers, based off user-input for amount of integers, and then sort them into an array. The problem is that the second method needs to be int[] but I cannot figure out what to make the return result. The instructions say it needs to be an int[] in the UML diagram, so I know it's not supposed to be void.
Java Code:
public void generateNewSecret() {
Random rand = new Random();{
for (int i=0; i<numDigitsSet; i++) {
secretNumber[i]= rand.nextInt(10);
System.out.println("" + secretNumber[i]);
[Code] .....
View Replies
View Related