Visa ett inlägg
Oläst 2012-12-02, 23:33 #16
Conny Westh Conny Westh är inte uppkopplad
Klarade millennium-buggen
 
Reg.datum: Aug 2005
Inlägg: 5 166
Conny Westh Conny Westh är inte uppkopplad
Klarade millennium-buggen
 
Reg.datum: Aug 2005
Inlägg: 5 166
Här är en mer aktuell artikel om Ruby: http://ruby.about.com/od/newinruby19...rs-In-Ruby.htm

Men observera att jag inte tycker Ruby är "sämre" eller dåligt på att hantera slumptal, det är datorn som hårdvara som sätter gränsen för hur slumpmässigt ett ta l kan vara, så samma förutsättningar gäller för alla programspråk som körs på samma dator.

Citat:
It can be useful in a range programs, typically games and simulations, to generate random numbers. While no computer can generate truly random numbers, Ruby does provide access to a method that will return pseudorandom numbers.

Not Exactly Random
No computer can generate truly random numbers purely by computation. The best they can do is to generate pseudorandom numbers, a sequence of numbers that appears random but is not random. To a human observer, these numbers are indeed random. There will be no short repeating sequences, and, at least to the human observer, be completely random. However, given enough time and motivation, the original seed can be discovered, the sequence recreated and the next number in the sequence guessed. For this reason, the methods discussed in this article should probably not be used to generate numbers that must be cryptographically secure.

As mentioned above, pseudorandom number generators PRNGs must be seeded in order to produce sequences that differ each time a new random number is generated. Remember that no method is magical, these seemingly random numbers are generated using relatively simple algorithms using relatively simple arithmetic. By seeding the PRNG, you're starting it off at a different point every time. If you didn't seed it, it would generate the same sequence of numbers each time. But, at least in Ruby, the developers have thought of this.
Conny Westh är inte uppkopplad   Svara med citatSvara med citat