Arithmetic statistics over number fields and function fields