public static String createRandomName ( String prefix ) { Preconditions . checkNotNull ( prefix , "Prefix must not be null." ) ; long nameOffset ; // obtain the next name offset by incrementing it atomically do { nameOffset = nextNameOffset . get ( ) ; } while ( ! nextNameOffset . compareAndSet ( nameOffset , nameOffset + 1L ) ) ; return prefix + ' ' + nameOffset ; }
Creates a random name of the form prefix_X where X is an increasing number .