Results 1 to 3 of 3

Thread: Random value

  1. #1
    Join Date
    Jul 2014
    Posts
    294

    Unanswered: Random value

    Hi,

    I am trying to generate a random values between 2 & 6.
    Tried with the below, But it is displaying values from 0-6.
    can some one correct me to place the minimum value in below query.

    SELECT INT(RAND() * 6) FROM SYSIBM.SYSDUMMY1

    thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so reduce the range and add an offset such as:-
    Code:
    SELECT (INT(RAND() * 4))+2 FROM SYSIBM.SYSDUMMY1
    the random number generator looks like its returning a values in range >= 0 and <=1

    you are then multiplying that value by 6, so your range is 0 to 6, by changing the multiplying factor to 4 you get 0 to 4, adding 2 after the number has been multiplied gives you the range 2 to 6

    the extra pair of brackets around the INT function are almost certainly superfluous

    ...rocket science it isn't.....
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2014
    Posts
    294
    Awesome Healdem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •