fix get Random value and sync socket write to prevent memory leak