× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Fri, Nov 11, 2022 at 7:53 PM Jay Vaughn <jeffersonvaughn@xxxxxxxxx> wrote:

anyone ever use this?

No. And I will expand on that in a minute.

if i do values rand(1000000) I get the same number everytime ... in strsql.

That is expected. And I will expand on that as well.

if I page up or down that number changes randomly...

This is very confusing to me. You are using "page up or down" in a way
that I don't understand, because I fail to see how scrolling the
STRSQL display up or down could change anything.

How can I retrieve a random number anytime I need one?

The simple answer is: Just use RAND(). And don't worry about the seeding.

Expanded response:

I have read the page Mark linked to. And I do understand it. Most of
the behavior described there aligns with the classic, traditional
model of pseudorandom number generation (going back to the days of
playing around with BASIC on 8-bit machines). Namely, a seed facility
is provided in case you want to do testing that requires RAND() to
produce the same sequence of numbers over and over. Then, when you're
satisfied with the results, your "production version" doesn't specify
a seed, and you really get just random-looking results.

So that's why it's expected that using the same seed would always
produce the same result.

However, that being said, I cannot actually reproduce the behavior
described on that page. Yes, calling RAND(1) will (and should) produce
the same number every time. But I can't get subsequent RAND()
invocations to produce the same sequence of numbers. For example, if I
log in, issue STRSQL, and enter VALUES RAND(1), RAND(), RAND(), I get
5.1387066255684077E-001 followed by two random-looking numbers. If I
do F9 to repeat the query, I get 5.1387066255684077E-001 followed by
two DIFFERENT random-looking numbers. Then if I log out, log back in
again, issue STRSQL again, enter VALUES RAND(1), RAND(), RAND() again,
I get 5.1387066255684077E-001 followed by two other random-looking
numbers that are different than any of the numbers I got in the
previous session. Do F9 again, get 5.1387066255684077E-001 followed by
yet another two random-looking numbers that are different from any of
the numbers I've seen before in either session.

I've tried several variations, interactively as well as submitted to
batch. Queries in loops. I have not been able to find any way to
produce the same sequence of results from RAND().

So, I don't know if maybe older versions of the operating system or
SQL engine produced repeating sequences. I sure as hell cannot make it
happen on the 7.4 box I'm currently using. (The page Mark linked to is
ostensibly for version 6.1, and the text mentions the V5R4 manual.) As
far as I can tell, the only way to produce the same sequence of
random-looking numbers is to use RAND(x), RAND(y), RAND(z), etc., with
the same sequence of x, y, z, etc. Which makes the parameter not
really a "seed" value anymore. It's more like RAND() has a single
seed, and the parameter is an ordinal index into that seed. If you
don't provide the parameter, a system-generated index (most likely
based on system time) is used.

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.