TSE: Documentation: Random()

15 views
Skip to first unread message

knud van eeden

unread,
Mar 17, 2026, 2:03:45 PMMar 17
to SemWare TSE Pro Text Editor, S.E. Mitchell
Hello,

Random() is completely missing from the inside TSE documentation:

 
 Q. TSE: Documentation: Random()

(see also the latest TSE 'read.me' file)

Syntax: INTEGER Random([integer lo[, integer hi]])

         1. If hi > lo, and lo >= 0:
             Returns an integer pseudo random number in the range lo .. hi,
             inclusive.

              E.g. if lo = 1 and hi = 100 returns an integer pseudo number in the range 1 .. 100
                   (inclusive)

         2. -If lo > 0: (and hi is 0 or < lo):
              Returns an integer pseudo random number in the range 0 .. lo - 1.

              E.g. if lo = 10 and hi = 0 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

              E.g. if lo = 10 and hi = 9 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

         3. -Otherwise, it returns an integer pseudo random number in the range
             0..MAXINT.

              In a 32-bits TSE that is an integer random value between 0 and 2^31 - 1 or thus 2147483647

Returns: An integer random value between 0 and MAXINT

Note:    The generator is based on code contributed by
         David Goodenough.
         Thanks David!

         SeedRand([integer seed])
         ------------------------

          if seed > 0, seed is used as the random number generator
          seed. Otherwise, seed is set to a value based on the system
          clock.

           E.g. SeedRand( 10 ) // here 10 is used as the random number generator seed

           E.g. SeedRand() // here the system clock is used as the random number generator seed

            1. -Under Windows, the Windows GetTickCount() function is
                called, which retrieves the number of milliseconds that
                have elapsed since the system was started, up to 49.7
                days.

            2. Under Linux:

                struct timeval tv;
                gettimeofday(&tv, NULL);
                return tv.tv_sec * 1000 + tv.tv_usec / 1000;

                 The tv argument is a struct timeval (as specified in
                 <sys/time.h>):

                  struct timeval {
                   time_t      tv_sec;     /* seconds */
                   suseconds_t tv_usec;    /* microseconds */
                  };

                   and gives the number of seconds and microseconds since the
                   Epoch.

Examples:

--- cut here: begin --------------------------------------------------

 PROC Main()
  //
  INTEGER randomValueI = 0
  INTEGER minI = 0
  INTEGER maxI = 0
  //
  // If lo = 0 (and hi > lo): Returns an integer pseudo random number in the range lo .. hi,
  minI = 0
  maxI = 100
  randomValueI = Random( minI, maxI )
  Warn( "Random integer value generated between: " + Str( minI ) + " and " + Str( maxI ) + " = " + Str( randomValueI ) ) // gives e.g. 70
  //
  // If lo > 0 (and hi > lo): Returns an integer pseudo random number in the range lo .. hi,
  minI = 1
  maxI = 100
  randomValueI = Random( minI, maxI )
  Warn( "Random integer value generated between: " + Str( minI ) + " and " + Str( maxI ) + " = " + Str( randomValueI ) ) // gives e.g. 70
  //
  // if lo > 0 (and hi is 0): Returns an integer pseudo random number in the range 0 .. lo - 1.
  minI = 8
  maxI = 0
  randomValueI = Random( minI, maxI )
  Warn( "Random integer value generated between: " + Str( maxI ) + " and " + Str( minI - 1 ) + " = " + Str( randomValueI ) ) // gives e.g. 6
  //
  // if lo > 0 (and hi is < lo): Returns an integer pseudo random number in the range 0 .. lo - 1.
  minI = 8
  maxI = 7
  randomValueI = Random( minI, maxI )
  Warn( "Random integer value generated between: " + Str( maxI ) + " and " + Str( minI - 1 ) + " = " + Str( randomValueI ) ) // gives e.g. 5
  //
 END

--- cut here: end ----------------------------------------------------



with friendly greetings
Knud van Eeden
Inline image

knud van eeden

unread,
Mar 17, 2026, 2:10:56 PMMar 17
to SemWare TSE Pro Text Editor, S.E. Mitchell
SeedRand() does not work.

Checking this...


knud van eeden

unread,
Mar 17, 2026, 2:19:17 PMMar 17
to SemWare TSE Pro Text Editor, S.E. Mitchell
Latest update:

 Q. TSE: Documentation: Random()

(see also the latest TSE 'read.me' file)

Syntax: INTEGER Random([integer lo[, integer hi]])

         1. If lo >= 0 (and hi > lo):

             Returns an integer pseudo random number in the range lo .. hi,
             inclusive.

              E.g. if lo = 0 and hi = 100 returns an integer pseudo number in the range 0 .. 100
                   (inclusive)

              E.g. if lo = 1 and hi = 100 returns an integer pseudo number in the range 1 .. 100
                   (inclusive)

         2. -If lo > 0: (and hi is 0 or < lo):

              Returns an integer pseudo random number in the range 0 .. lo - 1.

              E.g. if lo = 10 and hi = 0 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

              E.g. if lo = 10 and hi = 9 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

         3. -Otherwise, it returns an integer pseudo random number in the range
             0..MAXINT.

              In a 32-bits TSE that is an integer pseudo random value between 0 and 2^31 - 1 or thus 2147483647

Returns: An integer pseudo random value between 0 and MAXINT

Note:    The generator is based on code contributed by
         David Goodenough.
         Thanks David!

         SetRandomSeed([integer seed])

         ------------------------

          if seed > 0, seed is used as the random number generator
          seed. Otherwise, seed is set to a value based on the system
          clock.

           E.g. SetRandomSeed( 10 ) // here 10 is used as the random number generator seed

           E.g. SetRandomSeed() // here the system clock is used as the random number generator seed

            1. -Under Windows, the Windows GetTickCount() function is
                called, which retrieves the number of milliseconds that
                have elapsed since the system was started, up to 49.7
                days.

            2. Under Linux:

                struct timeval tv;
                gettimeofday(&tv, NULL);
                return tv.tv_sec * 1000 + tv.tv_usec / 1000;

                 The tv argument is a struct timeval (as specified in
                 <sys/time.h>):

                  struct timeval {
                   time_t      tv_sec;     /* seconds */
                   suseconds_t tv_usec;    /* microseconds */
                  };

                   and gives the number of seconds and microseconds since the
                   Epoch.

Examples:

--- cut here: begin --------------------------------------------------

 PROC Main()
  //
  INTEGER randomValueI = 0
  INTEGER minI = 0
  INTEGER maxI = 0
  //
  SetRandomSeed() // optional

knud van eeden

unread,
Mar 17, 2026, 5:09:48 PMMar 17
to SemWare TSE Pro Text Editor, S.E. Mitchell
Latest update 17 March 2026:

 Q. TSE: Documentation: Random()

(see also the latest TSE 'read.me' file)

Syntax: INTEGER Random([integer lo[, integer hi]])

         1. -If lo >= 0 (and hi > lo):

              Returns an integer pseudo random number in the range lo .. hi,
              inclusive.

               E.g. if lo = 0 and hi = 100 returns an integer pseudo number in the range 0 .. 100
                    (inclusive)

               E.g. if lo = 1 and hi = 100 returns an integer pseudo number in the range 1 .. 100
                    (inclusive)

         2. -If lo > 0 (and hi is 0 or < lo):

              Returns an integer pseudo random number in the range 0 .. lo - 1.

              E.g. if lo = 10 and hi = 0 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

              E.g. if lo = 10 and hi = 9 returns an integer pseudo number in the range 0 .. 9
                   (inclusive)

         3. -Otherwise, it returns an integer pseudo random number in the range
             0..MAXINT.

              In a 32-bits TSE that is an integer pseudo random value between 0 and 2^31 - 1
              or thus between 0 and 2147483647

Returns: An integer pseudo random value between 0 and MAXINT

Note:    The generator is based on code contributed by
         David Goodenough.
         Thanks David!

         SetRandomSeed([integer seed])

         ------------------------

          if seed > 0, seed is used as the random number generator
          seed. Otherwise, seed is set to a value based on the system
          clock.

           E.g. SetRandomSeed( 10 ) // here 10 is used as the random number generator seed.
                This will lead to an always fixed consecutive random value sequence.
                So this is handy when one has to debug and test TSE programs
                using those random numbers
                because the generation of those integer random number steps is fully reproducible.
                For example the first time the sequence is 1, 9, 12, 5, 21, ...
                Then the second time the

           E.g. SetRandomSeed() // here the system clock is used as the random number generator seed

            1. -Under Windows, the Windows GetTickCount() function is
                called, which retrieves the number of milliseconds that
                have elapsed since the system was started, up to 49.7
                days.

            2. Under Linux:

                struct timeval tv;
                gettimeofday(&tv, NULL);
                return tv.tv_sec * 1000 + tv.tv_usec / 1000;

                 The tv argument is a struct timeval (as specified in
                 <sys/time.h>):

                  struct timeval {
                   time_t      tv_sec;     /* seconds */
                   suseconds_t tv_usec;    /* microseconds */
                  };

                   and gives the number of seconds and microseconds since the
                   Epoch.

Examples:

--- cut here: begin --------------------------------------------------
 PROC Main()
  //
  INTEGER randomValueI = 0
  INTEGER minI = 0
  INTEGER maxI = 0
  //
  // SetRandomSeed() // optional, now much more random number sequences, because it depends on the system clock value.
  // SetRandomSeed( 10 ) // optional, now always the *same* random numbers sequences. Use this for testing and debugging those random numbers generated.
Reply all
Reply to author
Forward
0 new messages