Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Pseudorandom number

former_member1033672
Participant
0 Kudos

Hi, all... Im generating pseudorandom number by my own functional module with this code. Problem is, that it always returns same number. when i test class CL_ABAP_RANDOM* (all these classes), it returns good numbers. Please, do you see some problems in my code? thanks a lot

FUNCTION y0bi_cm_sample_psrnd_num_get.
*"----------------------------------------------------------------------
*"*"Lokální rozhraní:
*"  IMPORTING
*"     REFERENCE(X_XTIMESTAMP) TYPE  KENNZX OPTIONAL
*"  EXPORTING
*"     REFERENCE(Y_RANDOM_FLOAT) TYPE  CL_ABAP_RANDOM_PACKED=>P31_0
*"----------------------------------------------------------------------
  DATA: lr_random TYPE REF TO cl_abap_random_packed_dec14,
        l_timestamp TYPE timestamp,
        l_seed TYPE i.
  GET TIME STAMP FIELD l_timestamp.
  FREE: lr_random.
  IF x_xtimestamp EQ 'X'.

    l_seed = FRAC( l_timestamp ) * 1000000.
*TRY.
    lr_random = cl_abap_random_packed_dec14=>create(
                                                      seed   = l_seed
                                                      min    = '0'
                                                      max    = '1' ).

    .
* CATCH cx_abap_random .
*ENDTRY.

  ELSE.

    lr_random = cl_abap_random_packed_dec14=>create(
    min    = '0'
    max    = '1' ).
  ENDIF.

  y_random_float = lr_random->get_next( ).

ENDFUNCTION.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Dear Filip Kouba

Use this on your data declaration: tzntstmpl

instead of this:

timestamp

So your code will become like this:

l_timestamp TYPE tzntstmpl,

Kind Regards

/Ricardo Quintas

3 REPLIES 3

Former Member
0 Kudos

Dear Filip Kouba

Use this on your data declaration: tzntstmpl

instead of this:

timestamp

So your code will become like this:

l_timestamp TYPE tzntstmpl,

Kind Regards

/Ricardo Quintas

0 Kudos

thanx..the main problem was, that i used wrong data type with no decimals but same length )

rahul_mahajan
Active Participant
0 Kudos

Hi ,

Please see the coding in "RFTBB_MDG_CLASS" and you will get some idea.

I hope this will help you.

Regards,

Rahul Mahajan