If you only want three colours (or any other number under 256) you should consider using a palette image where, rather than storing three bytes for the RGB values of each pixel, you store a single byte which is the index into a palette (or table) of 256 colours. It is much more efficient. See discussion here.
So, the fastest and most memory efficient way is to initialise your image to random integers in range 0..2 and then push in a palette of your 3 colours:
import numpy as np
from PIL import Image
# Make a Numpy array 500x500 of random integers 0, 1 or 2
na = np.random.randint(0, 3, (500,500), np.uint8)
# Convert to PIL Image
im = Image.fromarray(na)
# Push in 3-entry palette with red, blue and yellow:
im.putpalette([255,0,0, 0,0,255, 255,255,0])
# Save
im.save('result.png')

That takes 1ms on my Mac compared to 180ms for iterating over the pixels and choosing one of 3 RGB colours for each, and creates a 50kB palletised output file rather than the 120kB RGB output file you get with the other method.