Weighted Random Spawning

I am working on a word game that I have made a bunch of letter prefabs for. Each prefab has a public float frequency variable. Where the “A” prefab frequency is 8.167 and the “Z” frequency is .074. How would I build a spawner that would instantiate prefabs randomly, but do so in such a way that A is more likely than Z based on the frequency variable?

Thanks,

Jason

Add the two values together. Create a random number between 0 and the sum. If it’s in the range [0-A], choose A, if it’s in range [A - A+Z], choose Z.