Source Code Cross Referenced for RandomAdaptor.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 Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.math.random;
017:
018:        import java.util.Random;
019:
020:        /**
021:         * Extension of <code>java.util.Random</code> wrapping a
022:         * {@link RandomGenerator}.   
023:         *
024:         * @since 1.1
025:         * @version $Revision:$ $Date$
026:         */
027:        public class RandomAdaptor extends Random implements  RandomGenerator {
028:
029:            /** Wrapped randomGenerator instance */
030:            private RandomGenerator randomGenerator = null;
031:
032:            /** 
033:             * Prevent instantiation without a generator argument
034:             */
035:            private RandomAdaptor() {
036:            }
037:
038:            /**
039:             * Construct a RandomAdaptor wrapping the supplied RandomGenerator.
040:             * 
041:             * @param randomGenerator  the wrapped generator
042:             */
043:            public RandomAdaptor(RandomGenerator randomGenerator) {
044:                this .randomGenerator = randomGenerator;
045:            }
046:
047:            /**
048:             * Factory method to create a <code>Random</code> using the supplied
049:             * <code>RandomGenerator</code>.
050:             * 
051:             * @param randomGenerator  wrapped RandomGenerator instance
052:             * @return a Random instance wrapping the RandomGenerator
053:             */
054:            public static Random createAdaptor(RandomGenerator randomGenerator) {
055:                return new RandomAdaptor(randomGenerator);
056:            }
057:
058:            /**
059:             * Returns the next pseudorandom, uniformly distributed
060:             * <code>boolean</code> value from this random number generator's
061:             * sequence.  
062:             * 
063:             * @return  the next pseudorandom, uniformly distributed
064:             * <code>boolean</code> value from this random number generator's
065:             * sequence
066:             */
067:            public boolean nextBoolean() {
068:                return randomGenerator.nextBoolean();
069:            }
070:
071:            /**
072:             * Generates random bytes and places them into a user-supplied 
073:             * byte array.  The number of random bytes produced is equal to 
074:             * the length of the byte array.
075:             * 
076:             * @param bytes the non-null byte array in which to put the 
077:             * random bytes
078:             */
079:            public void nextBytes(byte[] bytes) {
080:                randomGenerator.nextBytes(bytes);
081:            }
082:
083:            /**
084:             * Returns the next pseudorandom, uniformly distributed 
085:             * <code>double</code> value between <code>0.0</code> and
086:             * <code>1.0</code> from this random number generator's sequence.  
087:             *
088:             * @return  the next pseudorandom, uniformly distributed 
089:             *  <code>double</code> value between <code>0.0</code> and
090:             *  <code>1.0</code> from this random number generator's sequence
091:             */
092:            public double nextDouble() {
093:                return randomGenerator.nextDouble();
094:            }
095:
096:            /**
097:             * Returns the next pseudorandom, uniformly distributed <code>float</code>
098:             * value between <code>0.0</code> and <code>1.0</code> from this random
099:             * number generator's sequence.  
100:             *
101:             * @return  the next pseudorandom, uniformly distributed <code>float</code>
102:             * value between <code>0.0</code> and <code>1.0</code> from this
103:             * random number generator's sequence
104:             */
105:            public float nextFloat() {
106:                return randomGenerator.nextFloat();
107:            }
108:
109:            /**
110:             * Returns the next pseudorandom, Gaussian ("normally") distributed
111:             * <code>double</code> value with mean <code>0.0</code> and standard
112:             * deviation <code>1.0</code> from this random number generator's sequence.
113:             * 
114:             * @return  the next pseudorandom, Gaussian ("normally") distributed
115:             * <code>double</code> value with mean <code>0.0</code> and
116:             * standard deviation <code>1.0</code> from this random number
117:             *  generator's sequence
118:             */
119:            public double nextGaussian() {
120:                return randomGenerator.nextGaussian();
121:            }
122:
123:            /**
124:             * Returns the next pseudorandom, uniformly distributed <code>int</code>
125:             * value from this random number generator's sequence.  
126:             * All 2<font size="-1"><sup>32</sup></font> possible <tt>int</tt> values
127:             * should be produced with  (approximately) equal probability. 
128:             *
129:             * @return the next pseudorandom, uniformly distributed <code>int</code>
130:             *  value from this random number generator's sequence
131:             */
132:            public int nextInt() {
133:                return randomGenerator.nextInt();
134:            }
135:
136:            /**
137:             * Returns a pseudorandom, uniformly distributed <tt>int</tt> value
138:             * between 0 (inclusive) and the specified value (exclusive), drawn from
139:             * this random number generator's sequence.   
140:             *
141:             * @param n the bound on the random number to be returned.  Must be
142:             * positive.
143:             * @return  a pseudorandom, uniformly distributed <tt>int</tt>
144:             * value between 0 (inclusive) and n (exclusive).
145:             * @throws IllegalArgumentException  if n is not positive.
146:             */
147:            public int nextInt(int n) {
148:                return randomGenerator.nextInt(n);
149:            }
150:
151:            /**
152:             * Returns the next pseudorandom, uniformly distributed <code>long</code>
153:             * value from this random number generator's sequence.  All 
154:             * 2<font size="-1"><sup>64</sup></font> possible <tt>long</tt> values 
155:             * should be produced with (approximately) equal probability. 
156:             *
157:             * @return  the next pseudorandom, uniformly distributed <code>long</code>
158:             *value from this random number generator's sequence
159:             */
160:            public long nextLong() {
161:                return randomGenerator.nextLong();
162:            }
163:
164:            /**
165:             * Sets the seed of the underyling random number generator using a 
166:             * <code>long</code> seed.  Sequences of values generated starting with the
167:             * same seeds should be identical.
168:             *
169:             * @param seed the seed value
170:             */
171:            public void setSeed(long seed) {
172:                if (randomGenerator != null) { // required to avoid NPE in constructor
173:                    randomGenerator.setSeed(seed);
174:                }
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.