lapack
lapack copied to clipboard
SLARUV is inconsistent with SLARND
Description SLARAN and SLARUV handle the case of X(I) = 1.0 differently and so they may produce a different sequence of random numbers. They should be the same.
In SLARAN, a value of 1.0 is handled by advancing the seed. In SLARUV, the seed values, which are stored in I1, I2, I3, and I4, are advanced by 2: I1 = I1 + 2 I2 = I2 + 2 I3 = I3 + 2 I4 = I4 + 2 To be consistent with SLARAN, they should be given the values I1 = IT1 I2 = IT2 I3 = IT3 I4 = IT4 The same issue affects DLARUV as well.
A seed that triggers regenerating the random number is (2129, 3241, 0, 1). The attached test program with the current LAPACK code generates
% ./slarantst Enter n 10 Enter ISEED: 2129 3241 0 1 i SLARAN SLARNV 1 0.3970 0.8683 2 0.9163 0.4626 3 0.4606 0.7070 4 0.8368 0.7019 5 0.4997 0.8701 6 0.3226 0.8627 7 0.2293 0.3829 8 0.6391 0.7521 9 0.8207 0.3230 10 0.6012 0.6774
The expected result is
Enter ISEED: 2129 3241 0 1 i SLARAN SLARNV 1 0.3970 0.3970 2 0.9163 0.9163 3 0.4606 0.4606 4 0.8368 0.8368 5 0.4997 0.4997 6 0.3226 0.3226 7 0.2293 0.2293 8 0.6391 0.6391 9 0.8207 0.8207 10 0.6012 0.6012
program rantst integer i, j, k, l, n integer iseed(4) real x(128), y(128) real SLARAN iseed(1) = 0 iseed(2) = 0 iseed(3) = 0 iseed(4) = 1 write(,) 'Enter n' read(,) n n = min(128,n) do while (n > 0) write(,) 'Enter ISEED:' read(,) i, j, k, l ! ! Set x from SLARAN ! iseed(1) = i iseed(2) = j iseed(3) = k iseed(4) = l do idx = 1, n x(idx) = SLARAN( iseed ) end do ! ! Set y from SLARNV ! iseed(1) = i iseed(2) = j iseed(3) = k iseed(4) = l call SLARNV( 1, iseed, n, y ) ! ! Print the results ! write(,) ' i SLARAN SLARNV' do idx = 1, n write(*,'(i3,3x,f6.4,3x,f6.4)') idx, x(idx), y(idx) end do end do end program
Checklist
- [ ] I've included a minimal example to reproduce the issue
- [ ] I'd be willing to make a PR to solve this issue