Java Doc for RandomDataImpl.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » random » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Apache commons math 1.1 » org.apache.commons.math.random 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.math.random.RandomDataImpl

RandomDataImpl
public class RandomDataImpl implements RandomData,Serializable(Code)
Implements the RandomData interface using a RandomGenerator instance to generate non-secure data and a java.security.SecureRandom instance to provide data for the nextSecureXxx methods. If no RandomGenerator is provided in the constructor, the default is to use a generator based on java.util.Random . To plug in a different implementation, either implement RandomGenerator directly or extend AbstractRandomGenerator .

Supports reseeding the underlying pseudo-random number generator (PRNG). The SecurityProvider and Algorithm used by the SecureRandom instance can also be reset.

For details on the default PRNGs, see java.util.Random and java.security.SecureRandom .

Usage Notes:

  • Instance variables are used to maintain RandomGenerator and SecureRandom instances used in data generation. Therefore, to generate a random sequence of values or strings, you should use just one RandomDataImpl instance repeatedly.
  • The "secure" methods are *much* slower. These should be used only when a cryptographically secure random sequence is required. A secure random sequence is a sequence of pseudo-random values which, in addition to being well-dispersed (so no subsequence of values is an any more likely than other subsequence of the the same length), also has the additional property that knowledge of values generated up to any point in the sequence does not make it any easier to predict subsequent values.
  • When a new RandomDataImpl is created, the underlying random number generators are not intialized. If you do not explicitly seed the default non-secure generator, it is seeded with the current time in milliseconds on first use. The same holds for the secure generator. If you provide a RandomGenerator to the constructor, however, this generator is not reseeded by the constructor nor is it reseeded on first use.
  • The reSeed and reSeedSecure methods delegate to the corresponding methods on the underlying RandomGenerator andSecureRandom instances. Therefore, reSeed(long) fully resets the initial state of the non-secure random number generator (so that reseeding with a specific value always results in the same subsequent random sequence); whereas reSeedSecure(long) does not reinitialize the secure random number generator (so secure sequences started with calls to reseedSecure(long) won't be identical).
  • This implementation is not synchronized.

version:
   $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $



Constructor Summary
public  RandomDataImpl()
     Construct a RandomDataImpl.
public  RandomDataImpl(RandomGenerator rand)
     Construct a RandomDataImpl using the supplied RandomGenerator as the source of (non-secure) random data.

Method Summary
public  doublenextExponential(double mean)
     Returns a random value from an Exponential distribution with the given mean.
public  doublenextGaussian(double mu, double sigma)
     Generate a random value from a Normal (a.k.a.
public  StringnextHexString(int len)
     Algorithm Description: hex strings are generated using a 2-step process.
public  intnextInt(int lower, int upper)
     Generate a random int value uniformly distributed between lower and upper, inclusive.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound.
public  longnextLong(long lower, long upper)
     Generate a random long value uniformly distributed between lower and upper, inclusive.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound.
public  int[]nextPermutation(int n, int k)
     Uses a 2-cycle permutation shuffle to generate a random permutation. The shuffling process is described here.
Parameters:
  n - the population size.
Parameters:
  k - the number to choose.
public  longnextPoisson(double mean)
     Generates a random long value from the Poisson distribution with the given mean.

Algorithm Description: Uses simulation of a Poisson process using Uniform deviates, as described here.

The Poisson process (and hence value returned) is bounded by 1000 * mean.
Parameters:
  mean - mean of the Poisson distribution.

public  Object[]nextSample(Collection c, int k)
     Uses a 2-cycle permutation shuffle to generate a random permutation. Algorithm Description: Uses a 2-cycle permutation shuffle to generate a random permutation of c.size() and then returns the elements whose indexes correspond to the elements of the generated permutation. This technique is described, and proven to generate random samples, here
Parameters:
  c - Collection to sample from.
Parameters:
  k - sample size.
public  StringnextSecureHexString(int len)
     Algorithm Description: hex strings are generated in 40-byte segments using a 3-step process.
public  intnextSecureInt(int lower, int upper)
     Generate a random int value uniformly distributed between lower and upper, inclusive.
public  longnextSecureLong(long lower, long upper)
     Generate a random long value uniformly distributed between lower and upper, inclusive.
public  doublenextUniform(double lower, double upper)
     Algorithm Description: scales the output of Random.nextDouble(), but rejects 0 values (i.e., will generate another random double if Random.nextDouble() returns 0). This is necessary to provide a symmetric output interval (both endpoints excluded).
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound.
public  voidreSeed(long seed)
     Reseeds the random number generator with the supplied seed.
public  voidreSeed()
     Reseeds the random number generator with the current time in milliseconds.
public  voidreSeedSecure()
     Reseeds the secure random number generator with the current time in milliseconds.
public  voidreSeedSecure(long seed)
     Reseeds the secure random number generator with the supplied seed.
public  voidsetSecureAlgorithm(String algorithm, String provider)
     Sets the PRNG algorithm for the underlying SecureRandom instance using the Security Provider API.


Constructor Detail
RandomDataImpl
public RandomDataImpl()(Code)
Construct a RandomDataImpl.



RandomDataImpl
public RandomDataImpl(RandomGenerator rand)(Code)
Construct a RandomDataImpl using the supplied RandomGenerator as the source of (non-secure) random data.
Parameters:
  rand - the source of (non-secure) random data
since:
   1.1




Method Detail
nextExponential
public double nextExponential(double mean)(Code)
Returns a random value from an Exponential distribution with the given mean.

Algorithm Description: Uses the Inversion Method to generate exponentially distributed random values from uniform deviates.
Parameters:
  mean - the mean of the distribution the random Exponential value




nextGaussian
public double nextGaussian(double mu, double sigma)(Code)
Generate a random value from a Normal (a.k.a. Gaussian) distribution with the given mean, mu and the given standard deviation, sigma.
Parameters:
  mu - the mean of the distribution
Parameters:
  sigma - the standard deviation of the distribution the random Normal value



nextHexString
public String nextHexString(int len)(Code)
Algorithm Description: hex strings are generated using a 2-step process.
  1. len/2+1 binary bytes are generated using the underlying Random
  2. Each binary byte is translated into 2 hex digits

Parameters:
  len - the desired string length. the random string.



nextInt
public int nextInt(int lower, int upper)(Code)
Generate a random int value uniformly distributed between lower and upper, inclusive.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound. the random integer.



nextLong
public long nextLong(long lower, long upper)(Code)
Generate a random long value uniformly distributed between lower and upper, inclusive.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound. the random integer.



nextPermutation
public int[] nextPermutation(int n, int k)(Code)
Uses a 2-cycle permutation shuffle to generate a random permutation. The shuffling process is described here.
Parameters:
  n - the population size.
Parameters:
  k - the number to choose. the random permutation.



nextPoisson
public long nextPoisson(double mean)(Code)
Generates a random long value from the Poisson distribution with the given mean.

Algorithm Description: Uses simulation of a Poisson process using Uniform deviates, as described here.

The Poisson process (and hence value returned) is bounded by 1000 * mean.
Parameters:
  mean - mean of the Poisson distribution. the random Poisson value.




nextSample
public Object[] nextSample(Collection c, int k)(Code)
Uses a 2-cycle permutation shuffle to generate a random permutation. Algorithm Description: Uses a 2-cycle permutation shuffle to generate a random permutation of c.size() and then returns the elements whose indexes correspond to the elements of the generated permutation. This technique is described, and proven to generate random samples, here
Parameters:
  c - Collection to sample from.
Parameters:
  k - sample size. the random sample.



nextSecureHexString
public String nextSecureHexString(int len)(Code)
Algorithm Description: hex strings are generated in 40-byte segments using a 3-step process.
  1. 20 random bytes are generated using the underlying SecureRandom.
  2. SHA-1 hash is applied to yield a 20-byte binary digest.
  3. Each byte of the binary digest is converted to 2 hex digits.

Parameters:
  len - the length of the generated string the random string



nextSecureInt
public int nextSecureInt(int lower, int upper)(Code)
Generate a random int value uniformly distributed between lower and upper, inclusive. This algorithm uses a secure random number generator.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound. the random integer.



nextSecureLong
public long nextSecureLong(long lower, long upper)(Code)
Generate a random long value uniformly distributed between lower and upper, inclusive. This algorithm uses a secure random number generator.
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound. the random integer.



nextUniform
public double nextUniform(double lower, double upper)(Code)
Algorithm Description: scales the output of Random.nextDouble(), but rejects 0 values (i.e., will generate another random double if Random.nextDouble() returns 0). This is necessary to provide a symmetric output interval (both endpoints excluded).
Parameters:
  lower - the lower bound.
Parameters:
  upper - the upper bound. a uniformly distributed random value from the interval (lower, upper)



reSeed
public void reSeed(long seed)(Code)
Reseeds the random number generator with the supplied seed.

Will create and initialize if null.
Parameters:
  seed - the seed value to use




reSeed
public void reSeed()(Code)
Reseeds the random number generator with the current time in milliseconds.



reSeedSecure
public void reSeedSecure()(Code)
Reseeds the secure random number generator with the current time in milliseconds.

Will create and initialize if null.




reSeedSecure
public void reSeedSecure(long seed)(Code)
Reseeds the secure random number generator with the supplied seed.

Will create and initialize if null.
Parameters:
  seed - the seed value to use




setSecureAlgorithm
public void setSecureAlgorithm(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException(Code)
Sets the PRNG algorithm for the underlying SecureRandom instance using the Security Provider API. The Security Provider API is defined in Java Cryptography Architecture API Specification & Reference.

USAGE NOTE: This method carries significant overhead and may take several seconds to execute.


Parameters:
  algorithm - the name of the PRNG algorithm
Parameters:
  provider - the name of the provider
throws:
  NoSuchAlgorithmException - if the specified algorithmis not available
throws:
  NoSuchProviderException - if the specified provideris not installed



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.