protected void seed ( ) { if ( ! seeded . get ( ) ) { synchronized ( random ) { if ( ! seeded . get ( ) ) { getLogger ( ) . debug ( "Seeding random number generator" ) ; final GenerateRandomRequest request = new GenerateRandomRequest ( ) ; request . setNumberOfBytes ( 512 ) ; final GenerateRandomResult result = getKms ( ) . generateRandom ( request ) ; final ByteBuffer randomBytes = result . getPlaintext ( ) ; final byte [ ] bytes = new byte [ randomBytes . remaining ( ) ] ; randomBytes . get ( bytes ) ; random . setSeed ( bytes ) ; seeded . set ( true ) ; getLogger ( ) . debug ( "Seeded random number generator" ) ; } } } }
This seeds the random number generator using KMS if and only it hasn t already been seeded .