-- Finds a random position inside of the given part and returns a randomly rotated CFrame at that position

local function getRandomCFrameInVolume(partVolume)

    -- Calculate the position component of the random CFrame
    local x = randomGenerator:NextInteger(-partVolume.Size.X/2, partVolume.Size.X/2)
    local y = randomGenerator:NextInteger(-partVolume.Size.Y/2, partVolume.Size.Y/2)
    local z = randomGenerator:NextInteger(-partVolume.Size.Z/2, partVolume.Size.Z/2)
    local localOffset = Vector3.new(x, y, z)
    local worldOffset = partVolume.CFrame:pointToWorldSpace(localOffset)		

    -- Calculate the rotation component of the random CFrame
    local twoPi = math.pi * 2
    local xRotation = randomGenerator:NextNumber() * twoPi
    local yRotation = randomGenerator:NextNumber() * twoPi
    local zRotation = randomGenerator:NextNumber() * twoPi
    local CFrame = CFrame.Angles(xRotation, yRotation, zRotation)	

    -- Add the position and rotation together to get the full random CFrame
    CFrame = CFrame + worldOffset

    return CFrame
end
