RandomNumberLink

From OpenCog
Jump to: navigation, search

The RandomNumberLink is a type of FunctionLink that, when executed, generates a uniformly distributed random number. For example, the following:

(cog-execute!
    (RandomNumber (Number 0) (Number 1)))

will return a random number between zero and one. Another example:

(cog-evaluate!
  (GreaterThan
     (Number "0.5")
     (RandomNumber (Number 0) (Number 1))))

will return true half the time, and false the other half.

Warning!

The Value subsystem provides a superior mechanism for storing, recording, and working with fleeting and time-changing data. There are multiple problems with using Atoms for transient data, including: (a) it is CPU-intensive to create an Atom. Creating Values is much faster. (b) it is CPU-intensive to insert an Atom into the AtomSpace. Values are not stored in the atomsapce. For fleeting data, there is almost never any functional need for the indexing services that the AtomSpace provides, so its pointless to store fleeting data there, anyway. (c) it can become very difficult, sometimes impossible, to remove Atoms from the atomspace. This can happen when an Atom become a part of the outgoing set of another atom; in such a case, it would be illegal to delete the atom. For these three reasons, Values provide a superior mechanism for storing and working with fleeting numerical data. They just work better.

In other words, it would probably be better if a new RandomFloatValue class was created, such that each access to it returned a randomly-valued FloatValue with some distribution.

See also