RND() and phantoms(UV on win) and RANDOMIZE()

137 views
Skip to first unread message

Bob Dubery

unread,
May 2, 2025, 2:55:40 AMMay 2
to Pick and MultiValue Databases
Hi all,

A colleague of mine recently ran into an interesting problem. 

Code:
ID = DATE():TIME():RND(9999):".psm"
READU MailRec FROM sysmailout, ID LOCKED
*
* do some error handling
*
END

The error condition arose. The system had generated (or at least set a lock on) a previous record with the same ID. Given that TIME() is now to 1/1000 of a second, what are the chances? But it happened.

So she starts investigating. The code in question runs as a phantom. It turns out that RND() works differently in a phantom than if you just run the program from the command prompt. This code
FOR N=1 TO 10
PRINT RND(4):' ':
NEXT N

Produces different output each time when run from the prompt, but always the same output when run as a phantom. So something is happening to the seed value that the random number generator uses.

I have run the code as a phantom from two different terminal sessions. The output never changes.

So, in the case that sparked the investigation RND(9999) will always produce the same value.

But wait. There's more! This now brings us to RANDOMIZE().

From the manual: "Use the RANDOMIZE statement with an expression to make the RND
function generate the same sequence of random numbers each time the
program is run."

So I'm curious. What sort of task wants RND() to produce the same result each time?



Wol

unread,
May 2, 2025, 8:23:52 AMMay 2
to mvd...@googlegroups.com
On 02/05/2025 07:55, Bob Dubery wrote:
> So I'm curious. What sort of task wants RND() to produce the same result
> each time?

Otherwise known as a pseudo-random sequence ...


But it's not uncommon to want to use random numbers, but be able to
reproduce the results by repeating the run.

For example, I have a bunch of vans leaving site at the same time. I
want them in random order (because I don't want to favour one big client
over another), but it causes me headaches if I have a problem, re-run
the dispatch software, and all the runs get re-randomised ... (yes, this
is a real problem :-)

I'm sure other people will come up with similar scenarios.

Cheers,
Wol

Steven Martin Trimble

unread,
May 2, 2025, 9:02:42 AMMay 2
to mvd...@googlegroups.com
Looks like Ladybridge got it right.
This is commercial QM on Rocky Linux 8.
Here is my code:

CRT \TEST.RND\
FOR XX = 1 TO 10
   RESULT = RND(99999):RND(99999)
   RESULT = RESULT "R%10"
   CRT RESULT
NEXT XX

here is the phantom output after running a phantom process:
PHANTOM TEST.RND

LIST-ITEM $COMO
PH19_020525_075559
001: COMO file activated to PH19_020525_075559
002: Phantom 19 started at 07:55:59  02 MAY 2025
...
008: TEST.RND
009: 0742639355
010: 0959454061
011: 6737042577
012: 9258476989
013: 2261453317
014: 0126143532
015: 7652331084
016: 1821233601
017: 9419198829
018: 9221268770
019: Phantom 19 terminated at 07:55:59  2 MAY 2025

(notice above when the phantom started and ended at the same second in time)

and here is the terminal output:

TEST.RND
0005561584
0551473698
6914630140
2564967459
0955187822
2494497821
4717829415
0467609426
7199239346
8129294606

CDMI
Steven Trimble
(501) 772-3450 cell/text


--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mvdbms/0d86fa1d-d7b6-4b0c-be89-53581b73522cn%40googlegroups.com.

Bob Dubery

unread,
May 2, 2025, 10:13:12 AMMay 2
to Pick and MultiValue Databases
On Friday, 2 May 2025 at 14:23:52 UTC+2 Wol wrote:
For example, I have a bunch of vans leaving site at the same time. I
want them in random order (because I don't want to favour one big client
over another), but it causes me headaches if I have a problem, re-run
the dispatch software, and all the runs get re-randomised ... (yes, this
is a real problem :-)

Ah. Thank you for that. 
Message has been deleted

Bob Dubery

unread,
May 2, 2025, 10:18:52 AMMay 2
to Pick and MultiValue Databases
So what we found is that the terminal output will vary every time, but phantoms would produce the same output every time.  I could run the phantom once, have a cup of coffee, run a 2nd phantom and get the same output both times.

In the end this proved to give unique output every time when run as a phantom:
RANDOMIZE

tomma...@aircraftspruce.com

unread,
May 2, 2025, 11:17:44 AMMay 2
to mvd...@googlegroups.com

D3 also does it right.  

 

Here’s my test code

 

TEST.RND

001 TXT = ''

002 FOR I = 1 TO 10

003   TXT := ' ':RND(9999)

004 NEXT I

005 EXECUTE 'LOG-MSG ':TXT

006 END

 

Z TEST.RND multiple times gives different results each time on D3 Linux 10.2

 

Tom

--

You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.

Doug Averch

unread,
May 2, 2025, 4:19:30 PMMay 2
to Pick and MultiValue Databases
Code:
ID = DATE():TIME():RND(9999):".psm"

New UV Code might work better:
>ED BP TEST12
Top of "TEST12" in "BP", 3 lines, 69 characters.
*--: P
001:      ID = DATE():CONVERT('.','_',SYSTEM(12)):".psm"
002:      CRT ID
003:   END
Bottom.
*--: FIBR
Filed "TEST12" in file "BP" unchanged.
Compiling: Source = 'BP/TEST12', Object = 'BP.O/TEST12'


Compilation Complete.
2094251492_072.psm


Rex Gozar

unread,
May 3, 2025, 8:32:49 PMMay 3
to mvd...@googlegroups.com
In UV, I found that logging out and back in between tests produces the same results, just like running via PHANTOM. You have to use RANDOMIZE at least once during the UV session to get different RND results.

Also, on Windows at least, TIME() has a 16 millisecond resolution. So if you want unique ids based on TIME() you need to NAP 16 in between to get unique times. This also applies to calculating elapsed time between statements - any elapsed time in milliseconds will be off +/- 16.

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.

Wol

unread,
May 4, 2025, 4:31:19 AMMay 4
to mvd...@googlegroups.com
On 04/05/2025 01:32, Rex Gozar wrote:
> In UV, I found that logging out and back in between tests produces the
> same results, just like running via PHANTOM. You have to use RANDOMIZE
> at least once during the UV session to get different RND results.

That sounds to me then, that UV is using a PRNG (nothing wrong with
that), but the seed is initialised by default to zero and there's
nothing in UV itself to make sure it's properly set.

I'd be inclined to file a bug and say that UV should run RANDOMISE as
part of the login process to prevent this.

Cheers,
Wol

Jim Idle

unread,
May 8, 2025, 1:58:51 PMMay 8
to mvd...@googlegroups.com
This is what you are supposed to do. If you don’t use RANDOMIZE then there are no guarantees. People saying XYZ got it right are actually incorrect and incorrect in their assumptions about why they think they are correct. 

Use RANDOMIZE based upon a seed of your own devise or without any expression to use a time based seed (jBASE uses time since epoch). 

This is explained in the jBASE docs.

This is very basic CS. 

Jim

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.

tomma...@aircraftspruce.com

unread,
May 8, 2025, 2:01:24 PMMay 8
to mvd...@googlegroups.com

D3 doesn’t have a RANDOMIZE function or statement. The process executes srand() with a suitable seed on process startup (I presume).

 

 

From: 'Jim Idle' via Pick and MultiValue Databases <mvd...@googlegroups.com>
Sent: Thursday, May 8, 2025 10:59 AM
To: mvd...@googlegroups.com
Subject: Re: [mvdbms] RND() and phantoms(UV on win) and RANDOMIZE()

 

This is what you are supposed to do. If you don’t use RANDOMIZE then there are no guarantees. People saying XYZ got it right are actually incorrect and incorrect in their assumptions about why they think they are correct. 

Wol

unread,
May 8, 2025, 6:06:03 PMMay 8
to mvd...@googlegroups.com
On 08/05/2025 18:58, 'Jim Idle' via Pick and MultiValue Databases wrote:
> This is explained in the jBASE docs.
>
> This is very basic CS.

You're forgetting ... first of all a lot of us didn't start with Unix.
rnd and randomise are Unix calls to the best of my knowledge. Okay, the
same thing probably exists in other OSes (like Pick :-) but they may
have different names.

Second a lot of us don't have CS degrees - for example I've got no
formal computer education whatsoever. I don't think it existed for me at
school, and my degrees are Chemistry and Medical Tech.

And thirdly, most documentation is completely useless for teaching. If
you don't have a formal computer education this is exactly the sort of
stuff that is actually quite difficult to find out. I would probably
have guessed the problem pretty quickly, but then my big strength is
problem finding ...

Cheers,
Wol

Jim Idle

unread,
May 15, 2025, 4:16:07 PMMay 15
to mvd...@googlegroups.com
I didn’t claim it was a complex CS thing to get your head around, I said it was very basic. 

Rnd and Randomize have nothing to do with Unix. They can be implemented any way you like so long as they do the same basic thing. A deterministic pseudo random number generator is pretty easy to implement from scratch. 

Documentation should be read. Some is better than others, especially in the MV world. But these days a minute or two of google will give you what you need to know. ChatGPT will explain the concepts instantly.

Interestingly, randomness itself is in fact a very tricky subject, to the point that sone people have dedicated careers to it and related subjects. 

I’m not putting anyone down here BTW.  You don’t need CS to write a half decent app in BASIC. MV basic is generally a good way to create a business app that works. 

I do get a bit frustrated seeing people try to use the closed system versions of MV to do things that are trivial in jBASE, but involve huge hacky kludges in most , if not all, other systems. You don’t need formal training to use it, but writing it is a different matter. 

 However, I rarely get close to MV or even jBASE anymore. I monitor this group on the off chance I might say something useful. 

jIM 

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
---
You received this message because you are subscribed to the Google Groups "Pick and MultiValue Databases" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mvdbms+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages