From:

Date:

March 5, 2001 11:56Subject:

Re: [ID 20010305.005] "use integer" doesn't make rand() return integersMessage ID:

3AA3EF1F.62BFE717@rowman.comRobert Spier wrote: > > f> ----------------------------------------------------------------- > f> The following program doesn't print a sequence of integers as one > f> would expect. > > f> use integer; for(;;) { print rand 10; } > f> ----------------------------------------------------------------- > > I don't think this is a bug. > > perldoc -f rand says: > Returns a random fractional number greater than or equal t.... > > perldoc integer says: > integer - Perl pragma to compute arithmetic in integer > instead of double > > As "rand" isn't really a perl-level integer computation, (it can > almost be thought of as a black box that spits out "random fractional > numbers"), I think the proper thing is to just convert it by hand if > that's what you want: > > print int(rand 10); > > (The patch to make rand return an integer under use integers is > somewhat trivial.. > > if (PL_hints & HINT_INTEGER) > value = floor(value); > > before the push.. > > I think.) > > -R I would like one of the mathematicians on the list to confirm that using floor like that will in fact yield a random list; I suspect that it won't. In fact, that patch will return a list of zero's if the default rand() is called while "use integer" is in effect. John PeacockThread Previous | Thread Next

- [ID 20010305.005] "use integer" doesn't make rand() return integers by fanf
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John L. Allen
**Re: [ID 20010305.005] "use integer" doesn't make rand() return integers**by John Peacock- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Walt Mankowski
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John L. Allen
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Tony Finch
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by rspier
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Philip Newton
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Ronald J Kimball
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Nicholas Clark
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by abigail
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by Bryan C . Warnock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock
- Re: [ID 20010305.005] "use integer" doesn't make rand() return integers by John Peacock

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About