Cobol Foro

Cobol Foro (https://www.cobolforo.es/index.php)
-   PowerCOBOL (ActiveX, v4 - v11) (https://www.cobolforo.es/forumdisplay.php?f=9)
-   -   [Componente] Rutina Números Aleatorios (https://www.cobolforo.es/showthread.php?t=740)

Hrmcobol 11 de octubre de 2017 20:38

Rutina Números Aleatorios
 
Hola Amigos !!!!
Necesito una rutina, ocx, etc que genere números aleatorios de 3, 4 o 5 dígitos
Alguien tiene algo sobre este tema
Saludos !!!!

Fito 11 de octubre de 2017 22:44

Hola:

Nunca lo probé, pero a lo mejor esta función te sirve.

Cita:

RANDOM Function
This function returns a pseudo random value from uniform distributions.
Format
FUNCTION RANDOM [(argument-1)]
Argument
1. The type of argument-1 must be integer.
2. The value of argument-1 must be zero or a positive integer. It is used to
generate a pseudo-random string.
3. The RANDOM function with argument-1 will generate a pseudo-random string
using argument-1 as source.
4. If argument-1 is omitted in the RANDOM function first executed in the run unit, a
pseudo-random string is generated using zero as source.
5. When determining a random value from the same pseudo random string after
execution of the RANDOM function, argument-1 may be omitted. The value of
argument-1 is valid until the next RANDOM function having argument-1 appears.
Function Value
1. The function value is any value in the current pseudo-random string.
2. The range of the function value is:
0 ≤ function value < 1
3. If the value of argument-1 (source value) is the same as in a previous execution,
the same pseudo-random string is used.
Saludos.

Fito...

Hrmcobol 15 de octubre de 2017 01:26

Acá esta la respuesta FITO, me la paso un amigo !!


Código COBOL:
  1.  ENVIRONMENT     DIVISION.
  2.  DATA            DIVISION.
  3.  WORKING-STORAGE SECTION.
  4.  01  Misc.
  5.      05  Pseudo      Pic X.
  6.      05  Multi-Digit Pic 999999999V9(6).
  7.      05  Two-Digit   Pic 99999999.
  8.      05  Vary        Pic 99.  
  9.      05  hora        Pic 99999999.
  10.  PROCEDURE       DIVISION.
  11.  
  12.  Return-Pseudo.
  13.      ACCEPT HORA FROM TIME
  14.      Compute Multi-Digit = (Function Random (hora)) * 1
  15.      Display Two-Digit  " VARY" Vary " -----1--> " Multi-Digit  " --------> " hora  
  16.      Perform Varying Vary from 1 by 1
  17.        Until Vary > 50
  18.         Compute Multi-Digit = (Function Random) * 1
  19.         Move Multi-Digit to Two-Digit
  20.      Display Two-Digit  " VARY" Vary " --------> " Multi-Digit  " --------> " hora  
  21.      End-Perform


La franja horaria es GMT +2. Ahora son las 00:23.

Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.