Write a function that takes in an array of distinct integers as well as an integer k and returns the kth smallest number in that array in linear time, on average. The array could be sorted, but isn't necessarily so.
Sample input: [8, 5, 2, 9, 7, 6, 3], 3
Sample output: 5
Check this Python code.