File: random.java

package info (click to toggle)
groovy2 2.2.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 23,916 kB
  • sloc: java: 136,570; xml: 948; sh: 486; makefile: 67; ansic: 64
file content (32 lines) | stat: -rw-r--r-- 924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// $Id: random.java,v 1.2 2004-08-14 08:19:19 bfulgham Exp $
// http://shootout.alioth.debian.org/
//
// Brent Fulgham:  Changed to use 32-bit integers (like the C
// version), based on a suggestion by Yonik Seeley.

import java.text.*;

public class random {

    public static final int IM = 139968;
    public static final int IA = 3877;
    public static final int IC = 29573;

    public static void main(String args[]) {
        int N = Integer.parseInt(args[0]) - 1;
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(9);
        nf.setMinimumFractionDigits(9);
        nf.setGroupingUsed(false);

        while (N-- > 0) {
            gen_random(100);
        }
        System.out.println(nf.format(gen_random(100)));
    }

    public static int last = 42;
    public static double gen_random(double max) {
        return( max * (last = (last * IA + IC) % IM) / IM );
    }
}