Your script and your math are perfectly fine. The reason you are seeing the same angles repeated multiple times is because believe it or not, the math.random() function is not completely random.
How math.random() works exactly is that whenever you run the function, the script takes information from what is known as a "seed". A seed is a number that represents data–in this case, a sequence of numbers. If you set the seed the script picks number from as the same every time you run the game, you will get the same numbers returned every time. Whenever you test run a game in ROBLOX, math.random() picks from the same seed every time.
A way to get around this is to use the function math.randomseed(). Whenever this function is run, the seed for the random number generator is set to whatever number is inside of the parentheses. What you can do is put the function tick() as the parameter for the math.randomseed() function. tick() returns the amount of time the game has been running in seconds. After running math.randomseed(), the numbers generated by math.random() will be different, because it is taking the number sequence from a different seed.
Going back to your code, a way to make the bricks appear at a different location every time is to use the function math.randomseed() before you use the function math.random().
math.randomseed(tick())
part.CFrame = workspace.PlanetaryGravityB.Moon.CFrame
*CFrame.Angles(
math.rad(math.random(0,360)),
math.rad(math.random(0,360)),
math.rad(math.random(0,360)))
*CFrame.new(0,0,math.abs(diameter/2))
If you are still curious, there is actually a Wiki page on the ROBLOX Wiki that explains how random numbers work. You can visit that website by clicking here.
EDIT: I realize my explanation for seeds may not have been the best, so I'll provide you with an example. If you've ever played Minecraft, you may have heard of a "seed". In Minecraft's situation, a seed's data represents exactly what blocks you will get in your world. If you put the same seed in for every time you generate a world, you will get the same world every time. That's why when you randomize the seed when generating a world, you get a different world every time. The same seed will produce the same data every time.
1 comment
Thank you for the answer, but the parts are still mainly scattering on the tops and bottoms of the sphere, no matter how many times I reset the seed. Here is a reference image: https://pbs.twimg.com/media/DFAMvwCUQAEgKJE.jpg So there is definitely a flaw in my math that causes it to do this, and I'm looking for a more efficient way.