[BUILD] Randomization script refactoring

1) Refactored randomization logic to the top
2) Add logics to support window platforms
Emacs gets very confused about this type of formatting...  It doesn't handle statement that ends in '.' very well.