use rand instead of constant integer for better comparison
optimize portable solution for speed when htonl is available
shorten compromise solution
throw useless stuff away
formatting