001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.data;
031
032import gnu.trove.list.array.TIntArrayList;
033import gnu.trove.set.hash.TIntHashSet;
034
035import java.util.Date;
036import java.util.Random;
037
038import cern.jet.random.Uniform;
039import cern.jet.random.engine.MersenneTwister;
040
041/**
042 * Utility functions for creating random data
043 * 
044 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
045 */
046public class RandomData {
047        /**
048         * Returns a two dimensional array of pseudorandom, uniformly 
049         * distributed float values between min (inclusive) and 
050         * max (exclusive), drawn from this random number generator's sequence.
051         * The generator is seeded with the time at which the method is called.
052         * 
053         * @see cern.jet.random.Uniform
054         * 
055         * @param rows number of rows
056         * @param cols number of cols
057         * @param min minimum value
058         * @param max maximum value
059         * @return 2d array of random floats
060         */
061        public static float [][] getRandomFloatArray(int rows, int cols, float min, float max) {
062                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
063                float [][] data = new float[rows][cols];
064
065                for (int r=0; r<rows; r++)
066                        for (int c=0; c<cols; c++)
067                                data[r][c] = rnd.nextFloatFromTo(min, max);
068
069                return data;
070        }
071        
072        /**
073         * Returns a two dimensional array of pseudorandom, uniformly 
074         * distributed float values between min (inclusive) and 
075         * max (exclusive), drawn from this random number generator's sequence.
076         * 
077         * @see cern.jet.random.Uniform
078         * 
079         * @param rows number of rows
080         * @param cols number of cols
081         * @param min minimum value
082         * @param max maximum value
083         * @param seed random seed
084         * @return 2d array of random floats
085         */
086        public static float [][] getRandomFloatArray(int rows, int cols, float min, float max, int seed) {
087                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
088                float [][] data = new float[rows][cols];
089
090                for (int r=0; r<rows; r++)
091                        for (int c=0; c<cols; c++)
092                                data[r][c] = rnd.nextFloatFromTo(min, max);
093
094                return data;
095        }
096
097        /**
098         * Returns a two dimensional array of pseudorandom, uniformly 
099         * distributed double values between min (inclusive) and 
100         * max (exclusive), drawn from this random number generator's sequence.
101         * The generator is seeded with the time at which the method is called.
102         * 
103         * @see cern.jet.random.Uniform
104         * 
105         * @param rows number of rows
106         * @param cols number of cols
107         * @param min minimum value
108         * @param max maximum value
109         * @return 2d array of random doubles
110         */
111        public static double [][] getRandomDoubleArray(int rows, int cols, double min, double max) {
112                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
113                double [][] data = new double[rows][cols];
114
115                for (int r=0; r<rows; r++)
116                        for (int c=0; c<cols; c++)
117                                data[r][c] = rnd.nextDoubleFromTo(min, max);
118
119                return data;
120        }
121        
122        /**
123         * Returns a two dimensional array of pseudorandom, uniformly 
124         * distributed double values between min (inclusive) and 
125         * max (exclusive), drawn from this random number generator's sequence.
126         * 
127         * @see cern.jet.random.Uniform
128         * 
129         * @param rows number of rows
130         * @param cols number of cols
131         * @param min minimum value
132         * @param max maximum value
133         * @param seed random seed
134         * @return 2d array of random doubles
135         */
136        public static double [][] getRandomDoubleArray(int rows, int cols, double min, double max, int seed) {
137                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
138                double [][] data = new double[rows][cols];
139
140                for (int r=0; r<rows; r++)
141                        for (int c=0; c<cols; c++)
142                                data[r][c] = rnd.nextDoubleFromTo(min, max);
143
144                return data;
145        }
146        
147        /**
148         * Returns a two dimensional array of pseudorandom, uniformly 
149         * distributed int values between min (inclusive) and 
150         * max (exclusive), drawn from this random number generator's sequence.
151         * 
152         * @see cern.jet.random.Uniform
153         * 
154         * @param rows number of rows
155         * @param cols number of cols
156         * @param min minimum value
157         * @param max maximum value
158         * @param seed random seed
159         * @return 2d array of random ints
160         */
161        public static int [][] getRandomIntArray(int rows, int cols, int min, int max, int seed) {
162                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
163                int [][] data = new int[rows][cols];
164
165                for (int r=0; r<rows; r++)
166                        for (int c=0; c<cols; c++)
167                                data[r][c] = rnd.nextIntFromTo(min, max);
168
169                return data;
170        }
171        
172        /**
173         * Returns a two dimensional array of pseudorandom, uniformly 
174         * distributed long values between min (inclusive) and 
175         * max (exclusive), drawn from this random number generator's sequence.
176         * The generator is seeded with the time at which the method is called.
177         * 
178         * @see cern.jet.random.Uniform
179         * 
180         * @param rows number of rows
181         * @param cols number of cols
182         * @param min minimum value
183         * @param max maximum value
184         * @return 2d array of random longs
185         */
186        public static long [][] getRandomLongArray(int rows, int cols, long min, long max) {
187                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
188                long [][] data = new long[rows][cols];
189
190                for (int r=0; r<rows; r++)
191                        for (int c=0; c<cols; c++)
192                                data[r][c] = rnd.nextLongFromTo(min, max);
193
194                return data;
195        }
196        
197        /**
198         * Returns a two dimensional array of pseudorandom, uniformly 
199         * distributed long values between min (inclusive) and 
200         * max (exclusive), drawn from this random number generator's sequence.
201         * 
202         * @see cern.jet.random.Uniform
203         * 
204         * @param rows number of rows
205         * @param cols number of cols
206         * @param min minimum value
207         * @param max maximum value
208         * @param seed random seed
209         * @return 2d array of random longs
210         */
211        public static long [][] getRandomLongArray(int rows, int cols, long min, long max, int seed) {
212                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
213                long [][] data = new long[rows][cols];
214
215                for (int r=0; r<rows; r++)
216                        for (int c=0; c<cols; c++)
217                                data[r][c] = rnd.nextLongFromTo(min, max);
218
219                return data;
220        }
221
222        /**
223         * Returns a two dimensional array of pseudorandom, uniformly 
224         * distributed short values between min (inclusive) and 
225         * max (exclusive), drawn from this random number generator's sequence.
226         * 
227         * @see cern.jet.random.Uniform
228         * 
229         * @param rows number of rows
230         * @param cols number of cols
231         * @param min minimum value
232         * @param max maximum value
233         * @param seed random seed
234         * @return 2d array of random shorts
235         */
236        public static short [][] getRandomShortArray(int rows, int cols, short min, short max, int seed) {
237                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
238                short [][] data = new short[rows][cols];
239
240                for (int r=0; r<rows; r++)
241                        for (int c=0; c<cols; c++)
242                                data[r][c] = (short) rnd.nextIntFromTo(min, max);
243
244                return data;
245        }
246
247        /**
248         * Returns a two dimensional array of pseudorandom, uniformly 
249         * distributed byte values between min (inclusive) and 
250         * max (exclusive), drawn from this random number generator's sequence.
251         * The generator is seeded with the time at which the method is called.
252         * 
253         * @see cern.jet.random.Uniform
254         * 
255         * @param rows number of rows
256         * @param cols number of cols
257         * @param min minimum value
258         * @param max maximum value
259         * @return 2d array of random bytes
260         */
261        public static byte [][] getRandomByteArray(int rows, int cols, byte min, byte max) {
262                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
263                byte [][] data = new byte[rows][cols];
264
265                for (int r=0; r<rows; r++)
266                        for (int c=0; c<cols; c++)
267                                data[r][c] = (byte) rnd.nextIntFromTo(min, max);
268
269                return data;
270        }
271        
272        /**
273         * Returns a two dimensional array of pseudorandom, uniformly 
274         * distributed byte values between min (inclusive) and 
275         * max (exclusive), drawn from this random number generator's sequence.
276         * 
277         * @see cern.jet.random.Uniform
278         * 
279         * @param rows number of rows
280         * @param cols number of cols
281         * @param min minimum value
282         * @param max maximum value
283         * @param seed random seed
284         * @return 2d array of random bytes
285         */
286        public static byte [][] getRandomByteArray(int rows, int cols, byte min, byte max, int seed) {
287                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
288                byte [][] data = new byte[rows][cols];
289
290                for (int r=0; r<rows; r++)
291                        for (int c=0; c<cols; c++)
292                                data[r][c] = (byte) rnd.nextIntFromTo(min, max);
293
294                return data;
295        }
296
297        /**
298         * Returns an array of N unique pseudorandom, uniformly 
299         * distributed int values between min (inclusive) and 
300         * max (exclusive).
301         * 
302         * Internally this method creates an array of all the numbers
303         * in the range min->max and shuffles. The array is then cropped
304         * to N elements.
305         * 
306         * @param N number of unique random numbers 
307         * @param min minimum value
308         * @param max maximum value
309         * @return array of N unique ints
310         */
311        public static int [] getUniqueRandomIntsA(int N, int min, int max) {
312                return getUniqueRandomIntsA(N, min, max, new Random());
313        }
314
315        /**
316         * Returns an array of N unique pseudorandom, uniformly 
317         * distributed int values between min (inclusive) and 
318         * max (exclusive).
319         * 
320         * Internally this method uses a hashset to store numbers.
321         * The hashset is continually filled with random numbers in the
322         * range min->max until its size is N.
323         * 
324         * @param N number of unique random numbers 
325         * @param min minimum value
326         * @param max maximum value
327         * @return array of N unique ints
328         */
329        public static int [] getUniqueRandomIntsS(int N, int min, int max) {
330                return getUniqueRandomIntsS(N, min, max, new Random());
331        }
332
333        /**
334         * Returns an array of N unique pseudorandom, uniformly 
335         * distributed int values between min (inclusive) and 
336         * max (exclusive).
337         * 
338         * Internally this method chooses between the array and
339         * hashset methods depending on the ratio of the range between
340         * min and max and the number of ints required. 
341         * 
342         * @param N number of unique random numbers 
343         * @param min minimum value
344         * @param max maximum value
345         * @return array of N unique ints
346         */
347        public static int [] getUniqueRandomInts(int N, int min, int max) {
348                return getUniqueRandomInts(N, min, max, new Random());
349        }
350
351        /**
352         * Returns an array of N unique pseudorandom, uniformly 
353         * distributed int values between min (inclusive) and 
354         * max (exclusive).
355         * 
356         * Internally this method creates an array of all the numbers
357         * in the range min->max and shuffles. The array is then cropped
358         * to N elements.
359         * 
360         * @param N number of unique random numbers 
361         * @param min minimum value
362         * @param max maximum value
363         * @param rnd random generator to use
364         * @return array of N unique ints
365         */
366        public static int [] getUniqueRandomIntsA(int N, int min, int max, Random rnd) {
367                int rng = max-min;
368                if (rng < N)
369                        throw new IllegalArgumentException("Cannot generate more random numbers than the range allows");
370
371                TIntArrayList allData = new TIntArrayList(rng);
372
373                for (int i=min; i<max; i++)
374                        allData.add(i);
375
376                allData.shuffle(rnd);
377
378                int [] data = new int[N];
379                allData.toArray(data, 0, N);
380
381                return data;
382        }
383
384        /**
385         * Returns an array of N unique pseudorandom, uniformly 
386         * distributed int values between min (inclusive) and 
387         * max (exclusive).
388         * 
389         * Internally this method uses a hashset to store numbers.
390         * The hashset is continually filled with random numbers in the
391         * range min->max until its size is N.
392         * 
393         * @param N number of unique random numbers 
394         * @param min minimum value
395         * @param max maximum value
396         * @param rnd random generator to use
397         * @return array of N unique ints
398         */
399        public static int [] getUniqueRandomIntsS(int N, int min, int max, Random rnd) {
400                int rng = max-min;
401                if (rng < N)
402                        throw new IllegalArgumentException("Cannot generate more random numbers than the range allows");
403
404                TIntHashSet set = new TIntHashSet(N);
405
406                for (int i=0; i<N; i++) {
407                        while (true) {
408                                int r = rnd.nextInt(rng) + min;
409                                if (!set.contains(r)) {
410                                        set.add(r);
411                                        break;
412                                }
413                        }
414                }
415
416                return set.toArray();
417        }
418
419        /**
420         * Returns an array of N unique pseudorandom, uniformly 
421         * distributed int values between min (inclusive) and 
422         * max (exclusive).
423         * 
424         * Internally this method chooses between the array and
425         * hashset methods depending on the ratio of the range between
426         * min and max and the number of ints required. 
427         * 
428         * @param N number of unique random numbers 
429         * @param min minimum value
430         * @param max maximum value
431         * @param rng random generator to use
432         * @return array of N unique ints
433         */
434        public static int [] getUniqueRandomInts(int N, int min, int max, Random rng) {
435                //0.4 load factor seems a fairly sensible time-tradeoff
436                if (((double)N / (max-min)) > 0.4) {
437                        return getUniqueRandomIntsA(N, min, max,rng);
438                }
439                return getUniqueRandomIntsS(N, min, max,rng);
440        }
441
442        /**
443         * Returns a one dimensional array of pseudorandom, uniformly 
444         * distributed float values between min (inclusive) and 
445         * max (exclusive), drawn from this random number generator's sequence.
446         * The generator is seeded with the time at which the method is called.
447         * 
448         * @see cern.jet.random.Uniform
449         * 
450         * @param length length of array
451         * @param min minimum value
452         * @param max maximum value
453         * @return array of random floats
454         */
455        public static float [] getRandomFloatArray(int length, float min, float max) {
456                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
457                float [] data = new float[length];
458
459                for (int i=0; i<length; i++)
460                        data[i] = rnd.nextFloatFromTo(min, max);
461
462                return data;
463        }
464        
465        /**
466         * Returns a one dimensional array of pseudorandom, uniformly 
467         * distributed float values between min (inclusive) and 
468         * max (exclusive), drawn from this random number generator's sequence.
469         * 
470         * @see cern.jet.random.Uniform
471         * 
472         * @param length length of array
473         * @param min minimum value
474         * @param max maximum value
475         * @param seed random seed
476         * @return array of random floats
477         */
478        public static float [] getRandomFloatArray(int length, float min, float max, int seed) {
479                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
480                float [] data = new float[length];
481
482                for (int i=0; i<length; i++)
483                        data[i] = rnd.nextFloatFromTo(min, max);
484
485                return data;
486        }
487
488        /**
489         * Returns a one dimensional array of pseudorandom, uniformly 
490         * distributed double values between min (inclusive) and 
491         * max (exclusive), drawn from this random number generator's sequence.
492         * The generator is seeded with the time at which the method is called.
493         *  
494         * @see cern.jet.random.Uniform
495         * 
496         * @param length length of array
497         * @param min minimum value
498         * @param max maximum value
499         * @return array of random doubles
500         */
501        public static double [] getRandomDoubleArray(int length, double min, double max) {
502                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
503                double [] data = new double[length];
504
505                for (int i=0; i<length; i++)
506                        data[i] = rnd.nextDoubleFromTo(min, max);
507
508                return data;
509        }
510        
511        /**
512         * Returns a one dimensional array of pseudorandom, uniformly 
513         * distributed double values between min (inclusive) and 
514         * max (exclusive), drawn from this random number generator's sequence.
515         * 
516         * @see cern.jet.random.Uniform
517         * 
518         * @param length length of array
519         * @param min minimum value
520         * @param max maximum value
521         * @param seed random seed
522         * @return array of random doubles
523         */
524        public static double [] getRandomDoubleArray(int length, double min, double max, int seed) {
525                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
526                double [] data = new double[length];
527
528                for (int i=0; i<length; i++)
529                        data[i] = rnd.nextDoubleFromTo(min, max);
530
531                return data;
532        }
533
534        /**
535         * Returns a one dimensional array of pseudorandom, uniformly 
536         * distributed int values between min (inclusive) and 
537         * max (exclusive), drawn from this random number generator's sequence.
538         * The generator is seeded with the time at which the method is called.
539         * 
540         * @see cern.jet.random.Uniform
541         * 
542         * @param length length of array
543         * @param min minimum value
544         * @param max maximum value
545         * @return array of random ints
546         */
547        public static int [] getRandomIntArray(int length, int min, int max) {
548                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
549                int [] data = new int[length];
550
551                for (int i=0; i<length; i++)
552                        data[i] = rnd.nextIntFromTo(min, max);
553
554                return data;
555        }
556        
557        /**
558         * Returns a one dimensional array of pseudorandom, uniformly 
559         * distributed int values between min (inclusive) and 
560         * max (exclusive), drawn from this random number generator's sequence.
561         * 
562         * @see cern.jet.random.Uniform
563         * 
564         * @param length length of array
565         * @param min minimum value
566         * @param max maximum value
567         * @param seed random seed
568         * @return array of random ints
569         */
570        public static int [] getRandomIntArray(int length, int min, int max, int seed) {
571                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
572                int [] data = new int[length];
573
574                for (int i=0; i<length; i++)
575                        data[i] = rnd.nextIntFromTo(min, max);
576
577                return data;
578        }
579        
580        /**
581         * Returns a one dimensional array of pseudorandom, uniformly 
582         * distributed long values between min (inclusive) and 
583         * max (exclusive), drawn from this random number generator's sequence.
584         * The generator is seeded with the time at which the method is called.
585         * 
586         * @see cern.jet.random.Uniform
587         * 
588         * @param length length of array
589         * @param min minimum value
590         * @param max maximum value
591         * @return array of random longs
592         */
593        public static long [] getRandomLongArray(int length, long min, long max) {
594                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
595                long [] data = new long[length];
596
597                for (int i=0; i<length; i++)
598                        data[i] = rnd.nextLongFromTo(min, max);
599
600                return data;
601        }
602        
603        /**
604         * Returns a one dimensional array of pseudorandom, uniformly 
605         * distributed long values between min (inclusive) and 
606         * max (exclusive), drawn from this random number generator's sequence.
607         * 
608         * @see cern.jet.random.Uniform
609         * 
610         * @param length length of array
611         * @param min minimum value
612         * @param max maximum value
613         * @param seed random seed
614         * @return array of random longs
615         */
616        public static long [] getRandomLongArray(int length, long min, long max, int seed) {
617                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
618                long [] data = new long[length];
619
620                for (int i=0; i<length; i++)
621                        data[i] = rnd.nextLongFromTo(min, max);
622
623                return data;
624        }
625
626        /**
627         * Returns a one dimensional array of pseudorandom, uniformly 
628         * distributed short values between min (inclusive) and 
629         * max (exclusive), drawn from this random number generator's sequence.
630         * 
631         * @see cern.jet.random.Uniform
632         * 
633         * @param length length of array
634         * @param min minimum value
635         * @param max maximum value
636         * @param seed random seed
637         * @return array of random shorts
638         */
639        public static short [] getRandomShortArray(int length, short min, short max, int seed) {
640                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
641                short [] data = new short[length];
642
643                for (int i=0; i<length; i++)
644                        data[i] = (short) rnd.nextIntFromTo(min, max);
645
646                return data;
647        }
648        
649        /**
650         * Returns a one dimensional array of pseudorandom, uniformly 
651         * distributed byte values between min (inclusive) and 
652         * max (exclusive), drawn from this random number generator's sequence.
653         * The generator is seeded with the time at which the method is called.
654         * 
655         * @see cern.jet.random.Uniform
656         * 
657         * @param length length of array
658         * @param min minimum value
659         * @param max maximum value
660         * @return array of random bytes
661         */
662        public static byte [] getRandomByteArray(int length, byte min, byte max) {
663                Uniform rnd = new Uniform(min, max, new MersenneTwister(new Date()));
664                byte [] data = new byte[length];
665
666                for (int i=0; i<length; i++)
667                        data[i] = (byte) rnd.nextIntFromTo(min, max);
668
669                return data;
670        }
671        
672        /**
673         * Returns a one dimensional array of pseudorandom, uniformly 
674         * distributed byte values between min (inclusive) and 
675         * max (exclusive), drawn from this random number generator's sequence.
676         * 
677         * @see cern.jet.random.Uniform
678         * 
679         * @param length length of array
680         * @param min minimum value
681         * @param max maximum value
682         * @param seed random seed
683         * @return array of random bytes
684         */
685        public static byte [] getRandomByteArray(int length, byte min, byte max, int seed) {
686                Uniform rnd = new Uniform(min, max, new MersenneTwister(seed));
687                byte [] data = new byte[length];
688
689                for (int i=0; i<length; i++)
690                        data[i] = (byte) rnd.nextIntFromTo(min, max);
691
692                return data;
693        }
694
695        /**
696         * Returns a one dimensional array of pseudorandom, uniformly 
697         * distributed float values between min (inclusive) and 
698         * max (exclusive), drawn from this random number generator's sequence.
699         * 
700         * @see cern.jet.random.Uniform
701         * 
702         * @param length length of array
703         * @param min minimum value
704         * @param max maximum value
705         * @param mt Mersenne twister
706         * @return array of random floats
707         */
708        public static float [] getRandomFloatArray(int length, float min, float max, MersenneTwister mt) {
709                Uniform rnd = new Uniform(min, max, mt);
710                float [] data = new float[length];
711
712                for (int i=0; i<length; i++)
713                        data[i] = rnd.nextFloatFromTo(min, max);
714
715                return data;
716        }
717
718        /**
719         * Returns a one dimensional array of pseudorandom, uniformly 
720         * distributed double values between min (inclusive) and 
721         * max (exclusive), drawn from this random number generator's sequence.
722         * 
723         * @see cern.jet.random.Uniform
724         * 
725         * @param length length of array
726         * @param min minimum value
727         * @param max maximum value
728         * @param mt Mersenne twister
729         * @return array of random doubles
730         */
731        public static double [] getRandomDoubleArray(int length, double min, double max, MersenneTwister mt) {
732                Uniform rnd = new Uniform(min, max, mt);
733                double [] data = new double[length];
734
735                for (int i=0; i<length; i++)
736                        data[i] = rnd.nextDoubleFromTo(min, max);
737
738                return data;
739        }
740
741        /**
742         * Returns a one dimensional array of pseudorandom, uniformly 
743         * distributed int values between min (inclusive) and 
744         * max (exclusive), drawn from this random number generator's sequence.
745         * 
746         * @see cern.jet.random.Uniform
747         * 
748         * @param length length of array
749         * @param min minimum value
750         * @param max maximum value
751         * @param mt Mersenne twister
752         * @return array of random ints
753         */
754        public static int [] getRandomIntArray(int length, int min, int max, MersenneTwister mt) {
755                Uniform rnd = new Uniform(min, max, mt);
756                int [] data = new int[length];
757
758                for (int i=0; i<length; i++)
759                        data[i] = rnd.nextIntFromTo(min, max);
760
761                return data;
762        }
763
764        /**
765         * Returns a one dimensional array of pseudorandom, uniformly 
766         * distributed long values between min (inclusive) and 
767         * max (exclusive), drawn from this random number generator's sequence.
768         * 
769         * @see cern.jet.random.Uniform
770         * 
771         * @param length length of array
772         * @param min minimum value
773         * @param max maximum value
774         * @param mt Mersenne twister
775         * @return array of random longs
776         */
777        public static long [] getRandomLongArray(int length, long min, long max, MersenneTwister mt) {
778                Uniform rnd = new Uniform(min, max, mt);
779                long [] data = new long[length];
780
781                for (int i=0; i<length; i++)
782                        data[i] = rnd.nextLongFromTo(min, max);
783
784                return data;
785        }
786
787        /**
788         * Returns a one dimensional array of pseudorandom, uniformly 
789         * distributed short values between min (inclusive) and 
790         * max (exclusive), drawn from this random number generator's sequence.
791         * 
792         * @see cern.jet.random.Uniform
793         * 
794         * @param length length of array
795         * @param min minimum value
796         * @param max maximum value
797         * @param mt Mersenne twister
798         * @return array of random shorts
799         */
800        public static short [] getRandomShortArray(int length, short min, short max, MersenneTwister mt) {
801                Uniform rnd = new Uniform(min, max, mt);
802                short [] data = new short[length];
803
804                for (int i=0; i<length; i++)
805                        data[i] = (short) rnd.nextIntFromTo(min, max);
806
807                return data;
808        }
809
810        /**
811         * Returns a one dimensional array of pseudorandom, uniformly 
812         * distributed byte values between min (inclusive) and 
813         * max (exclusive), drawn from this random number generator's sequence.
814         * 
815         * @see cern.jet.random.Uniform
816         * 
817         * @param length length of array
818         * @param min minimum value
819         * @param max maximum value
820         * @param mt Mersenne twister
821         * @return array of random bytes
822         */
823        public static byte [] getRandomByteArray(int length, byte min, byte max, MersenneTwister mt) {
824                Uniform rnd = new Uniform(min, max, mt);
825                byte [] data = new byte[length];
826
827                for (int i=0; i<length; i++)
828                        data[i] = (byte) rnd.nextIntFromTo(min, max);
829
830                return data;
831        }
832}