Jump to content

Random method

- - - - -

  • Please log in to reply
8 replies to this topic

#1
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
I want to write a method named random.

Description: suppose i have 10 number in hand. when i run my program the number will display randomly. but there must not be any repeatation. (number 10 is urbitary)

Please help me to write the method or class

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
If you store the numbers in a list, then you can remove them from the list as they are found. It will need to be part of a class to store the numbers in the list, of course.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
As far as generating your numbers, you can use the Math.random method or the java.util.Random class.

#4
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
I am thinking about to create a class/method/package. I dont want to use any existing function.

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
At some point, you will need to generate a random number bounded by the number of available numbers. You really shouldn't roll your own random number generator.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Sorry sir, could not understand meaning. please write in easy english.

WingedPanther said:

At some point, you will need to generate a random number bounded by the number of available numbers. You really shouldn't roll your own random number generator.


#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
What I mean is that you will have to use a random number generator someplace in your algorithm. You have a choice, use the one in the library, or try to make your own. Unfortunately, making your own that works well is not easy, and is not a good idea.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
To get an idea of what goes into a PRNG (pseudo random number generator), you can check out the source code of the SIMD-Oriented Fast Mersenne Twister.
Wow I changed my sig!

#9
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
or How We Learned to Cheat at Online Poker: A Study in Software Security - Developer.com
lots of useful information about pseudo random number generator.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users