programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Create Random Number

Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
What is concept to generate random number without using java.util.scanner/math.random or any other class.i mean to say how we can make any program which give us random number....??

author
Posts: 23956
142
• Number of slices to send:
Optional 'thank-you' note:

Not sure what you are asking.... are you asking how does the Random class generates a random number?

Henry

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:

Henry Wong wrote:
Not sure what you are asking.... are you asking how does the Random class generates a random number?

Henry

thanks for response
yes i have same question that how Random class generate random no.?

Henry Wong
author
Posts: 23956
142
• Number of slices to send:
Optional 'thank-you' note:
The Random class uses a pseudo random number algorithm to generate a series of numbers that approximate random numbers -- it is pure mathematics. There is nothing random about these numbers; given the same starting number (seed) it will generate the same exact series of numbers, every time. It is completely deterministic.

By default, it uses the current time as the seed... so, the series of numbers won't be the same, since the time changes.

Henry

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
thanks
but what is seed there??

Java Cowboy
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:
Generating random numbers in software is a complicated subject. There is a whole list of algorithms to do this, based on mathematical theorems. Many of those algorithms start from some starting number called a seed.

See Pseudorandom number generator for detailed information.

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
thanks
But if i want to make a program to generate random no. without using any function,how should i start to approach that?

sparsh

Henry Wong
author
Posts: 23956
142
• Number of slices to send:
Optional 'thank-you' note:

sparsh khandelwal wrote:
But if i want to make a program to generate random no. without using any function,how should i start to approach that?

The link provided by Jesper have some ideas on how to write your own. Remember, when writing one of your own, there is no exact right answer -- just test it with lots of samples, and if the distribution looks random (and even distributed) then you succeeded.

Henry

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
thanks
but i am a beginner in java and i need some more stuff for create random number generator,so please provide me some more stuff so that i can easily understand the thing.

Bartender
Posts: 2700
• Number of slices to send:
Optional 'thank-you' note:
Why do you want to create a random number generator? It isn't something beginners (or experienced programmers) do. Creating one isn't hard but creating a good one is extremely hard.

Marshal
Posts: 79469
379
• Number of slices to send:
Optional 'thank-you' note:

Wouter Oet wrote:. . . It isn't something beginners . . . do. . . .

In which case I shall move this thread.

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
please provide me some more stuff,i want to create random number generator.!

author and iconoclast
Posts: 24207
46
• Number of slices to send:
Optional 'thank-you' note:

sparsh khandelwal wrote:please provide me some more stuff,i want to create random number generator.!

What sort of "stuff" are you expecting? You have a link that explains how random number generators work. What else do you want, exactly?

sparsh khandelwal
Ranch Hand
Posts: 76
• Number of slices to send:
Optional 'thank-you' note:
it is in compact form,i need everything in detail.!
Because i am at the stage on which i not know how to take the current time as seed too.
so please recommend me (books,notes,tutorial) which is fully dedicated to create random number generator.

Ranch Hand
Posts: 1491
• Number of slices to send:
Optional 'thank-you' note:
Try Apache commons random generator

Jesper de Jong
Java Cowboy
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:
The Wikipedia link is an excellent starting point to do research on algorithms to generate random numbers. If you really want to implement your own random number generator, you'll have to start reading the article and do some more research. The article List of random number generators contains a list, with links and explanations in as much detail as you want, of different algorithms.

You'll need to study those and determine which one is suitable for your purposes, and then write Java code that implements your chosen algorithm.

It's not a question that you can solve in five minutes, and don't expect that someone will post the complete code here so that you don't have to put any effort into it...

sparsh khandelwal wrote:Because i am at the stage on which i not know how to take the current time as seed too.

You get the current time (in milliseconds since 1 January 1970, 00:00:00 UTC) in Java by calling System.currentTimeMillis(). Study the algorithms to understand what you're supposed to do with the seed.

kri shan
Ranch Hand
Posts: 1491
• Number of slices to send:
Optional 'thank-you' note:
Check this link for Apached commons random generator.
http://commons.apache.org/math/apidocs/org/apache/commons/math/random/RandomGenerator.html

lowercase baba
Posts: 13091
67
• Number of slices to send:
Optional 'thank-you' note:

sparsh khandelwal wrote:it is in compact form,i need everything in detail.!
Because i am at the stage on which i not know how to take the current time as seed too.
so please recommend me (books,notes,tutorial) which is fully dedicated to create random number generator.

I don't think you understand how we do things here. We don't hand out code. We are here to help you learn. We will answer specific questions as best we can. However, a general, overly broad "I need you to tell me everything" will not get you much of a response around here.

Do you know how to write a "hello world" application? Can you compile and run it?

Do you know how to write java code at all? Do you know how to write modular programs? Do yo know how to analyze a problem and break it down into it's components?

IMHO, getting the current time as the seed would be one of the LAST things you'd want to do. I would think you'd want to use the same seed each time during your development process, so you can see how good or bad your algorithm is.

Show us what you have so far, ask SPECIFIC and FOCUSED questions, and you'll get all kinds of help. Continue saying "Tell me everything I need to know about how to do this" will most likely be met with silence. Reply when people ask you questions. Read the articles people point you to, and acknowledge you have read them.

 Don't get me started about those stupid light bulbs.