octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UBsans and rand()


From: Rik
Subject: Re: UBsans and rand()
Date: Sun, 11 Aug 2013 08:22:49 -0700

On 08/10/2013 10:00 AM, address@hidden wrote:
If Matlab's rand('state',s) accepts negative numbers, then ours does
> as well. The best we can do is map any possible input values to the
> uint32_t array in a deterministic way.
Does Matlab, in point of fact, accept negative numbers?  Could somebody test that?

And if it does, is it doing anything more than taking the absolute value and then feeding it into the algorithm?

The MathWorks has switched to rng() for initializing the random number generator and the documentation states:

"rng(sd) seeds the random number generator using the nonnegative integer sd so that rand, randi, and randn produce a predictable sequence of numbers."

So negative values are not currently documented as being accepted.  Rather than dig deeply into the C++ compiler specifications it might be easier just to restrict the input that Octave accepts.

--Rik

reply via email to

[Prev in Thread] Current Thread [Next in Thread]