org.linkedin.util-core/src/main/java/org/linkedin/util/codec/CodecUtils.java
public static Random createRandom(String password)
  {
    if(password == null)
      return null;

    byte[] bytes;

    try
    {
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      bytes = md.digest(password.getBytes("UTF-8"));
    }
    catch(NoSuchAlgorithmException e)
    {
      // should not happen
      throw new RuntimeException(e);
    }
    catch(UnsupportedEncodingException e)
    {
      // should not happen
      throw new RuntimeException(e);
    }

    int len = bytes.length;

    // we only take at most 6 bytes => 48 bits
    if(len > 6)
      len = 6;

    long seed = 0;

    if(len > 0)
    {
      seed = bytes[0];

      for(int i = 1; i < len; i++)
      {
        seed <<=  8;
        seed |= bytes[i];
      }
    }

    int k = 0;

    for(int i = len; i < bytes.length; i++)
    {
      seed ^= (((long) bytes[i]) << (k * 8));
      if(k++ == 5)
        k = 0;
    }

    return new Random(seed);
  }
public static Random createRandom(String password)
  {
    if(password == null)
      return null;

    byte[] bytes;

    try
    {
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      bytes = md.digest(password.getBytes("UTF-8"));
    }
    catch(NoSuchAlgorithmException e)
    {
      // should not happen
      throw new RuntimeException(e);
    }
    catch(UnsupportedEncodingException e)
    {
      // should not happen
      throw new RuntimeException(e);
    }

    int len = bytes.length;

    // we only take at most 6 bytes => 48 bits
    if(len > 6)
      len = 6;

    long seed = 0;

    if(len > 0)
    {
      seed = bytes[0];

      for(int i = 1; i < len; i++)
      {
        seed <<=  8;
        seed |= bytes[i];
      }
    }

    int k = 0;

    for(int i = len; i < bytes.length; i++)
    {
      seed ^= (((long) bytes[i]) << (k * 8));
      if(k++ == 5)
        k = 0;
    }

    return new Random(seed);
  }
public static Random createRandom ( String password ) { if ( password == null ) return null ; byte [ ] bytes ; try { MessageDigest md = MessageDigest . getInstance ( "SHA-1" ) ; bytes = md . digest ( password . getBytes ( "UTF-8" ) ) ; } catch ( NoSuchAlgorithmException e ) { // should not happen throw new RuntimeException ( e ) ; } catch ( UnsupportedEncodingException e ) { // should not happen throw new RuntimeException ( e ) ; } int len = bytes . length ; // we only take at most 6 bytes => 48 bits if ( len > 6 ) len = 6 ; long seed = 0 ; if ( len > 0 ) { seed = bytes [ 0 ] ; for ( int i = 1 ; i < len ; i ++ ) { seed <<= 8 ; seed |= bytes [ i ] ; } } int k = 0 ; for ( int i = len ; i < bytes . length ; i ++ ) { seed ^= ( ( ( long ) bytes [ i ] ) << ( k * 8 ) ) ; if ( k ++ == 5 ) k = 0 ; } return new Random ( seed ) ; }
Create a <code>Random</code> object by extracting the seed from the password.
Create a <code > Random< / code > object by extracting the seed from the password .