Potential obstacles
Generating game environments randomly isn't as simple as it may first appear. It's not just a case of generating a random number within the bounds of a level. Though this might technically work, there is no control there, and the environment that is generated as a result will have many flaws. Objects may overlap, be located in unreachable places, or be laid out in a poor order. In order to generate meaningful and playable levels there needs to be more control.
Keeping within the bounds of a level
I'm sure that at some point we've all played a game where an item spawned beyond our reach. It's infuriating to have that shiny new item just out of reach, but this can easily happen when spawning objects randomly around a map. Therefore, it's important to establish accurate bounds within which the objects can be spawned.
As you can imagine, the complexity of this task will match the complexity of your environment. Thankfully for us, our level is described as a simple 2D array....