Assume lotto numbers go from 1 to N. Assume that you have to pick n numbers.
The chances of the first number you picked being among the numbers drawn is 1/N.
The chances of the second number picked is included is 1/(N-1).
So for n numbers the combined probability is 1/(N(N-1)(N-2)...(N-n+1))=(N-n)!/N!.
But there are n! ways of arranging n numbers (n(n-1)(n-2)...3*2*1) so the total probability is n!(N-n)!/N!.
When n=6 and N=40 this comes to 0.00000026 approx (1 in 3.8 million).