473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Random Number

8 New Member
Hi,

I am wondering if I create a random number

Random random = new Random()

Is there a way to print out the random number?

I tried to System.out.println("random number = " + random);

and it printout "random number = java.util.Random@9304b1"
Feb 25 '08 #1
9 1073
Laharl
849 Recognized Expert Contributor
Calling the Random() method like that does not give you a random number, it gives you an object of the Random class, whose toString() seems to be java.util.Random@<its address in memory>. To actually get a random number, call the class's methods, next() or nextInt() are probably what you want.
Feb 25 '08 #2
sukatoa
539 Contributor
Hi,

I am wondering if I create a random number

Random random = new Random()

Is there a way to print out the random number?

I tried to System.out.println("random number = " + random);

and it printout "random number = java.util.Random@9304b1"


You can also directly use
Expand|Select|Wrap|Line Numbers
  1. new Random().nextInt(integer);
Feb 25 '08 #3
BigDaddyLH
1,216 Recognized Expert Top Contributor
You can also directly use
Expand|Select|Wrap|Line Numbers
  1. new Random().nextInt(integer);
That's great until you want another one ;-)
Feb 26 '08 #4
sukatoa
539 Contributor
That's great until you want another one ;-)
Ohh!! I forgot, Codes are restricted.. hehehehhh OK!! But i could not change it anymore... Next time i will be careful...

BigDaddy, i have a thread there Proper Invoking .COM file, can you advice me for that? That is the last part of my program...
Feb 26 '08 #5
newgal
8 New Member
Thanks, random.nextInt() gives a printout.

If a number is seeded,
Random random = new Random(10)
I find that it also does not print the given seed. Is it because it's also not called from the method? So the real seed is not 10, but someother number right?
Feb 26 '08 #6
BigDaddyLH
1,216 Recognized Expert Top Contributor
Thanks, random.nextInt() gives a printout.

If a number is seeded,
Random random = new Random(10)
I find that it also does not print the given seed. Is it because it's also not called from the method? So the real seed is not 10, but someother number right?
I'm note sure you know what the seed is. It's just a value used for the pseudo random number generator's internal state. It is not the value that nextInt will return on its next invocation, for example. As the API states:

The seed is the initial value of the internal state of the pseudorandom number generator which is maintained by method next(int).
Feb 26 '08 #7
BigDaddyLH
1,216 Recognized Expert Top Contributor
BigDaddy, i have a thread there Proper Invoking .COM file, can you advice me for that? That is the last part of my program...
Sorry, I'm not one for going outside of Java...
Feb 26 '08 #8
newgal
8 New Member
Got ya! Thanks very much.
Feb 26 '08 #9
Doegon
14 New Member
Hi,

I am wondering if I create a random number

Random random = new Random()

Is there a way to print out the random number?

I tried to System.out.println("random number = " + random);

and it printout "random number = java.util.Random@9304b1"
yes there is,but you need to understand that after creating the random number generator object you should use its methods to get a random nuber and store it in a variable/identifier then print the variable.

what you did is try to print the object so since random is an object it holds the address referencing the object so @9304b1 is the address of the object

fing the random class API and you will get the methods,good luck...hope it helps
Feb 27 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Virus | last post by:
Ok well what I am trying to do is have 1.) the background color to change randomly with 5 different colors.(change on page load) 2,) 10 different quotes randomly fadeing in and out in random...
4
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
10
by: Johnny Snead | last post by:
Hey guys, Need help with this random sort algorithm private void cmdQuestion_Click(object sender, System.EventArgs e) { Random rnd = new Random(); //initialize rnd to new random object...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
8
by: Daniel | last post by:
Hey guys Using Random(), how random is it, is it possible to be predicted? I have a requirement for a very good random number generator. I was doing something such as: Random randomSeed = new...
4
by: fatimahtaher | last post by:
Hi, I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
8
by: Anil Gupte | last post by:
I had someone write a random number generator in C# (I am more of a VB programmer) and they came up with the following: public string GetRand(int count) { string number = ""; for (int i=0;...
2
by: alishaikhji | last post by:
I am working on a program which will need several different integer and float random numbers at different stages, for example: - At one point, I need a random number (float) in the range 0.1 to 10.0...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.