/*
 * Copyright 2016 Marcel Reutegger
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.github.mreutegg.laszip4j.clib;

import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.util.Random;

public final class Cstdlib {

    public static final int RAND_MAX = Character.MAX_VALUE;

    private static final ByteBuffer SEED = ByteBuffer.allocate(32)
            .put(SecureRandom.getSeed(32));

    private static Random RANDOM = newSecureRandom(SEED);

    private Cstdlib() {
    }

    public static double atof(String s) {
        return Double.parseDouble(s.trim());
    }

    public static int atoi(String s) {
        return Integer.parseInt(s.trim());
    }

    public static void srand(int seed) {
        ByteBuffer seedBytes = SEED;
        if (seed != 1) {
            seedBytes = ByteBuffer.allocate(4).putInt(seed);
        }
        RANDOM = newSecureRandom(seedBytes);
    }

    public static int rand() {
        return RANDOM.nextInt(RAND_MAX + 1);
    }

    private static SecureRandom newSecureRandom(ByteBuffer seed) {
        SecureRandom r = new SecureRandom();
        r.setSeed(seed.array());
        return r;
    }
}

@@ -777,16 +777,63 @@
 Buffer;%0A
+import java.security.NoSuchAlgorithmException;%0A
 import j
@@ -1729,32 +1729,50 @@
 eBuffer seed) %7B%0A
+        try %7B%0A    
         SecureRa
@@ -1779,20 +1779,16 @@
 ndom r =
- new
  SecureR
@@ -1796,12 +1796,38 @@
 ndom
-();%0A
+.getInstance(%22SHA1PRNG%22);%0A    
     
@@ -1859,24 +1859,28 @@
 ));%0A        
+    
 return r;%0A  
@@ -1877,16 +1877,120 @@
 turn r;%0A
+        %7D catch (NoSuchAlgorithmException e) %7B%0A            throw new IllegalStateException();%0A        %7D%0A
     %7D%0A%7D%0A

Use a PRNG algorithm