Showing posts from December, 2014

How to create random files and folders?

During this week of one hour of code, this post refers to a quick and easy way to create random files and folders. Nothing complicated as it was the case in some previous posts. This one came out of a real at-work problem in Bing : in order to validate some scenarios, we wanted a cheap and quick way to create thousands of files and folders, subfolders too, in a semi-random fashion. A simple task. The 50 lines of code down below did the trick. I think the two key interesting points of this code for the novice developer are the following: a) A way to achieve something with probability N is to simply do something like this: Rand(0, 100) < N. I've seen junior developers trying complicated things - this should do the trick. These are the spots in the code where we do it. b) State control. Notice that that we use a simple depth variable to determine when we can come down a folder, or to keep creating subfolders. Just by increasing and decreasing this variable controls where we ar