src/HTTPClient/DefaultAuthHandler.java
/**
     * Generate <var>num</var> bytes of random data.
     *
     * @param num  the number of bytes to generate
     * @return a byte array of random data
     */
Generate num bytes of random data.
@param num  the number of bytes to generate
@return a byte array of random data
Generate num bytes of random data . @param num the number of bytes to generate @return a byte array of random data
private static byte[] gen_random_bytes(int num)
    {
	try
	{
	    FileInputStream rnd = new FileInputStream("/dev/random");
	    DataInputStream din = new DataInputStream(rnd);
	    byte[] data = new byte[num];
	    din.readFully(data);
	    try { din.close(); } catch (IOException ioe) { }
	    return data;
	}
	catch (Throwable t)
	    { }
	/* This is probably a much better generator, but it can be awfully
	 * slow (~ 6 secs / byte on my old LX)
	 */
	/* this is faster, but needs to be done better... */
	byte[] data = new byte[num];
	try
	{
	    long fm = Runtime.getRuntime().freeMemory();
	    data[0] = (byte) (fm & 0xFF);
	    data[1] = (byte) ((fm >>  8) & 0xFF);
	    int h = data.hashCode();
	    data[2] = (byte) (h & 0xFF);
	    data[3] = (byte) ((h >>  8) & 0xFF);
	    data[4] = (byte) ((h >> 16) & 0xFF);
	    data[5] = (byte) ((h >> 24) & 0xFF);
	    long time = System.currentTimeMillis();
	    data[6] = (byte) (time & 0xFF);
	    data[7] = (byte) ((time >>  8) & 0xFF);
	}
	catch (ArrayIndexOutOfBoundsException aioobe)
	    { }
	return data;
    }
private static byte [ ] gen_random_bytes ( int num ) { try { FileInputStream rnd = new FileInputStream ( "/dev/random" ) ; DataInputStream din = new DataInputStream ( rnd ) ; byte [ ] data = new byte [ num ] ; din . readFully ( data ) ; try { din . close ( ) ; } catch ( IOException ioe ) { } return data ; } catch ( Throwable t ) { } /* This is probably a much better generator, but it can be awfully
	 * slow (~ 6 secs / byte on my old LX)
	 */ /* this is faster, but needs to be done better... */ byte [ ] data = new byte [ num ] ; try { long fm = Runtime . getRuntime ( ) . freeMemory ( ) ; data [ 0 ] = ( byte ) ( fm & 0xFF ) ; data [ 1 ] = ( byte ) ( ( fm >> 8 ) & 0xFF ) ; int h = data . hashCode ( ) ; data [ 2 ] = ( byte ) ( h & 0xFF ) ; data [ 3 ] = ( byte ) ( ( h >> 8 ) & 0xFF ) ; data [ 4 ] = ( byte ) ( ( h >> 16 ) & 0xFF ) ; data [ 5 ] = ( byte ) ( ( h >> 24 ) & 0xFF ) ; long time = System . currentTimeMillis ( ) ; data [ 6 ] = ( byte ) ( time & 0xFF ) ; data [ 7 ] = ( byte ) ( ( time >> 8 ) & 0xFF ) ; } catch ( ArrayIndexOutOfBoundsException aioobe ) { } return data ; }
Generate <var>num</var> bytes of random data.
Generate <var > num< / var > bytes of random data .
// first try /dev/random //return new java.security.SecureRandom().getSeed(num);