Assets aren't assigned randomly?


Perhaps I’m misreading the book (I’m obviously missing something) but when the assets are assigned to the employees, I thought the use of the randomIndex integer was to assign random assets to each employee. But every time when I run it, I get the exact same results as the example in the book.

Can anyone explain this to me?


Computers can’t really generate random numbers – they just look random. If you want a different set of pseudo-random numbers, you need to “seed” the random number generator. Here I’m seeding it with the current time:

Just put that code near the beginning of your main() function.


Ah, I see, thanks. So if you don’t seed the random number generator, what does the computer use?


That is kind of a deep question, so I’m going to punt to wikipedia: … _generator


Acctually… just use this function instead to try more quasi-randomness. arc4random() . It’ll give you closer to what you want. That said, it might make some of Aaron’s other examples less understandable related to ARC and memory management… If you change that function permanently, it will make grokking his examples a bit later harder.


And today I learn a new word. Thank you Myrhillion.


And to think that we use to call it “Mastery” or “Guru”

generates a warning!

generates a warning!


That warning is harmless; you can make it shut up by explicitly casting the return value from time() to an integer.


The compiler wants to make sure you know you’re losing precision (time returns a 64 bit integer, srandom takes a 32 bit integer as argument).


[quote=“PHBeagle”]And today I learn a new word. Thank you Myrhillion.


And to think that we use to call it “Mastery” or “Guru”[/quote]

What a blasphemous article! :smiling_imp:

Grok is an idea that Robert Heinlein coined in his book Stranger in a Strange Land one of my favorite SciFi books ever.


And that’s actually where I learned to use it back in the late 70’s. I also heard it used on the compsci campuse of Umass in the mid 90’s then it seemed to spring up all over as the internet started getting ubiquitous.

Heinlein is still amazing, I would love to see an accurate version of Starship Troopers made into a film… not that pile of stink that Hollywood made. Now with proper CGI, the power armor and shooting the mobile infantry onto planet could be more true to the book. The opening battle as a short film would be awesome too.