# Confusion about result of FIR All-pass filter design

I try to design a FIR All-pass filter with random phase in the frequency domain. I am a bit confused by my result and am not sure if the reason is a programming error or a misconception about convolution and impulse response of myself. I use Python and Numpy:

import numpy as np

mag = np.ones(129) # magnitude is unitiy
phase = np.zeros(129)
random_numbers = (np.random.rand(128)-0.5)*2.0
phase[1:] = random_numbers * np.pi # phase is random except for dc offset
spec = mag*np.exp(phase * 1j) # get spectrum from magnitude and phase
coefficients = np.fft.irfft(spec) # do inverse fft to get coefficents, result is of length 256


If I do a fft on my coefficients the magnitude looks nearly right. My first question: Why is the highest frequency suppressed? And secondly, if I use my coefficients for convolving with an impulse, I thought that should reproduce the coefficients? But it does not. Why are there these "random variations" around 1.0?

impulse = np.zeros(256, dtype=np.float64) # create impulse
impulse[256/2] = 1.0
result = np.convolve(impulse, coefficients, "same") # convolve it Any explanations or hints are much appreciated!

The dip at Nyquist has to do with the fact that you didn't assign the value $0$ to the desired phase at Nyquist. You correctly assigned $0$ to the phase at DC, but you have to do the same at Nyquist, because a filter with real-valued coefficients has a real-valued frequency response at DC and Nyquist. So you just need 127 random numbers, not 128.