Global random integer generation in a range

Hello,
I need a way to achieve a global random integer generation in a range.
I tried FMs QF05_RANDOM_INTEGER and RANDOM_I4 without success because every time I call them from an object, always get the same number
For example, FM RANDOM_I4 with RND_MIN = 1 and RND_MAX = 5 gets RND_VALUE = 1 and FM QF05_RANDOM_INTEGER with RAN_INT_MAX = 5 and AN_INT_MIN = 1 gets RAN_INT = 3.
How can I get a global (with memory) random number generator?
Regards and thanks in advance.

Hey run the code below, it will give you different numbers.
data RAN_INT like QF00-RAN_INT.
data G_RAN_SEED like QF00-RAN_SEED.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
    EXPORTING
         RAN_INT_MAX   = 5
         RAN_INT_MIN   = 1
    IMPORTING
         RAN_INT       = RAN_INT
    EXCEPTIONS
         INVALID_INPUT = 1
         OTHERS        = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write ran_int.
G_RAN_SEED = ran_int.
CALL FUNCTION 'QF05_RANDOM_SAVE_SEED'
    EXPORTING
         RAN_SEED_NEXT = G_RAN_SEED

Similar Messages

  • Five Random Number Generation between numbers 10-20

    I want to generate 5 random numbers (U32) between a range of 120 and 180 with equal distribution. Can i do it? I tried using white noise generation VI, but it gives numbers from [-a,a].
    Thanks in advance.

    stevem181 wrote:
    Note that the 120 and 180 values occur about half as often as the other values.
    To correct that flaw, multiply by 61 and round to -infinity. For example like this:
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    RandomRange.png ‏17 KB

  • Random Integer - Code help

    Hi, I'm having a bit of a problem with a program I am making for class. I'm not asking you guys to do my work for me, I just simply need some guidance as to what I am doing wrong.
    Alright, what I am suppose to write as a program that takes two user defined integers and then prints a random integer from between the two user numbers. This is the code I have thus far:
            int a = Integer.parseInt(args[0]);
         int b = Integer.parseInt(args[1]);
         double r = Math.random();
         int low = a + (int) (r * a);
         int high = a - (int) (r * b);
         int result = low + high;
         System.out.println(result);For the most part it seems to work, however it will only work if the two user defined numbers are more then 10 digits of each other. I.E. 10 20 will work fine, however 1 5 will not, 10 15, etc.
    Any help would be greatly appreciated!
    Edited by: KnivesACE on Sep 18, 2008 11:32 AM

    Stianbl wrote:
    lower = 1000;  // your lower integer value
    upper = 2000; // the larger one of your two integers
    double rand = Math.random();
    int result = lower + (int)((upper - lower)* rand);
    http://forums.sun.com/thread.jspa?threadID=590266&messageID=3948731
    The question here is whether the two limits are to be included in the random range? In your solution 2000 will never happen. If you want it to it should look like this,
    int result = lower + (int)((upper - lower + 1)* rand);

  • What algorithm does Excel 2010 use for Pseudo Random Number Generation (MT19937?)

    Does Excel 2010+ use the Mersenne Twister (MT19937) algorithm for Pseudo Random Number Generation (PRNG), implemented by the RAND() function?
    This has been a nagging question for some time now, with "hints" that it indeed does.  However, a relatively thorough search turns up no definitive documentation.  The most direct indication is perhaps given by Guy Melard [Ref 9] where
    he tests Excel 2010's RAND() function using the Crush battery of tests in TestU01 by L'Ecuyer & Simard.  Melard references a "semi-official" indication that Microsoft did indeed implement MT19937 for the RAND() function in
    Excel 2010, but this reference no longer seems to be available. http://office.microsoft.com/enus/excel-help/about-solver-HP005198368.aspx?pid=CH010004571033.
    The other references below [Ref 1-10] document the history of the statistical suitability of the PRNG and probability distributions in various versions of Excel.  This includes the Wichmann-Hill PRNG implementations supposedly (arguably) used in
    Excel 2003 & 2007 for random number generation.  But still, we have no answer as to which PRNG algorithm is used in
    Excel 2010 (and 2013 for that matter).
    Microsoft indicates that RAND() has been improved in Excel 2010; Microsoft states, "...and the RAND function now uses a new random number algorithm." (see https://support.office.com/en-ca/article/Whats-New-Changes-made-to-Excel-functions-355d08c8-8358-4ecb-b6eb-e2e443e98aac). 
    But no details are given on the actual algorithm.  This is critical for Monte Carlo methods and many other applications.
    Any help would be much appreciated. Thanks.
    [Ref 1] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 97. 
    Computational Statistics & Data Analysis. Vol. 31 No. 1, pp 27-37. July 1999.
    http://users.df.uba.ar/cobelli/LaboratoriosBasicos/excel97.pdf
    [Ref 2]L. Knüsel.  On the accuracy of the statistical distributions in Microsoft Excel 97. Computational Statistics & Data Analysis. Vol. 26 No. 3, pp 375-377. January 1998.
    http://www.sciencedirect.com/science/article/pii/S0167947397817562
    [Ref 3]B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2000 and Excel XP. 
    Computational Statistics & Data Analysis. Vol.40 No. 4, pp 713-721. October 2002.
    https://www.researchgate.net/publication/222672996_On_the_accuracy_of_statistical_procedures_in_Microsoft_Excel_2000_and_Excel_XP/links/00b4951c314aac4702000000.pdf
    [Ref 4] B. McCullough, B. Wilson.  On the Accuracy of Statistical Procedures in Microsoft Excel 2003. 
    Computational Statistics & Data Analysis. Vol.49. No. 4, pp 1244-1252. June 2005.
    http://www.pucrs.br/famat/viali/tic_literatura/artigos/planilhas/msexcel.pdf
    [Ref 5] L. Knüsel. On the accuracy of statistical distributions in Microsoft Excel 2003. Computational Statistics & Data Analysis, Vol. 48, No. 3, pp 445-449. March 2005.
    http://www.sciencedirect.com/science/article/pii/S0167947304000337
    [Ref 6]B. McCullough, D.Heiser.  On the Accuracy of Statistical Procedures in Microsoft Excel 2007. 
    Computational Statistics & Data Analysis. Vol.52. No. 10, pp 4570-4578. June 2008.
    http://users.df.uba.ar/mricci/F1ByG2013/excel2007.pdf
    [Ref 7] A. Yalta. The Accuracy of Statistical Distributions in Microsoft<sup>®</sup> Excel 2007. Computational Statistics & Data Anlaysis. Vol. 52 No. 10, pp 4579 – 4586. June 2008.
    http://www.sciencedirect.com/science/article/pii/S0167947308001618
    [Ref 8] B. McCullough.  Microsoft Excel’s ‘Not The Wichmann-Hill’ Random Number Generators. Computational Statistics and Data Analysis. Vol.52. No. 10, pp 4587-4593. June 2008.
    http://www.sciencedirect.com/science/article/pii/S016794730800162X
    [Ref 9] G. Melard.  On the Accuracy of Statistical Procedures in Microsoft Excel 2010. Computational Statistics. Vol.29 No. 5, pp 1095-1128. October 2014.
    http://homepages.ulb.ac.be/~gmelard/rech/gmelard_csda23.pdf
    [Ref 10] L. Knüsel.  On the Accuracy of Statistical Distributions in Microsoft Excel 2010. Department of Statistics - University of Munich, Germany.
    http://www.csdassn.org/software_reports/excel2011.pdf

    I found the same KB article:
    https://support.microsoft.com/en-us/kb/828795
    This was introduced (according to the article) in Excel 2003. Perhaps the references in notes 2 and 3 might help.
    The article describes combining the results of 3 generators, each similar to a Multiply With Carry (MWC) generator, but with zero carry. MWC generators do very well on the Diehard battery of randomness tests (mentioned in your references), and have
    very long periods. But using zero carry makes no sense to me.
    Combining the three generators only helps if the periods of the 3 are relatively prime (despite what the article implies). Then the period of the result will be the product of the 3 periods. But without knowing the theory behind these generators, I have
    no idea what the periods would be. The formulas for MWC generators fail here.
    Richard Mueller - MVP Directory Services

  • Random integer that is a multiple of 5?

    So far I got the program to tell me if the user's inputted letter is right or wrong, but how can I have the computer tell the user what slot the guessed letter (if correct) is in? I.e. the letter "e" is in the first and last slots.
    This is what I have so far, but all it says is the previously used wrong letters and previously guessed right letters, but not in the order of the word.
              JOptionPane.showMessageDialog (null, "You have guessed all of the following letters incorrectly: \n" + guessedWrongLetters + "\n \nYou have guessed all of the following correct letters: \n" + guessedRightLetters);Also, How can I generate a random integer between one and 250 that is a multiple of five? I.e. 5, 10, 15, etc. I'm using the String.substring (+start+, end) method to choose a random word from a single variable "wordlist" that contains 50 five letter words.
    This is what I have, but it just chooses at random letter for the first part of the substring, and adds five to that chosen letter for the second part. So it sometimes chooses something in the middle of a word.
    compNumOne = 1 + randy.nextInt (245);
               compNumTwo = compNumOne + 5;
               itsComputersWord = itsComputersWordList.substring(compNumOne, compNumTwo);Here is the word list:
         private String itsComputersWordList = "firstbibleshoeshoneyearthgloveapplechildshipsboatsaortaacidsallowroadsburntbusesdocksbucksbuddydudesudderembedemberelveseggedentryebonydunesdoweldozeldoorsdiverdisksdirksdinerdualsfrothelbowfryerfrozefrownfretsfumedgullsneckshairyhabitlinenlilacmedal";}Edited by: Pluberus on Nov 20, 2008 4:17 PM - Fixed a mistake.

    Pluberus wrote:
    What about something like this:?
                    indexHolder = itsComputersWord.indexOf(itsUsersLetter);
    if (indexHolder == 0)
    JOptionPane.showMessageDialog (null, "The letter you guessed is the first letter of the secret word.");
    if (indexHolder == 1)
    JOptionPane.showMessageDialog (null, "The letter you guessed is the second letter of the secret word.");
    if (indexHolder == 2)
    JOptionPane.showMessageDialog (null, "The letter you guessed is the third letter of the secret word.");
    if (indexHolder == 3)
    JOptionPane.showMessageDialog (null, "The letter you guessed is the fourth letter of the secret word.");               
    if (indexHolder == 4)
    JOptionPane.showMessageDialog (null, "The letter you guessed is the fifth letter of the secret word.");By the way, is there an easier way to do what I just did? instead of all the multiple ifs?
    Also, since none of my words have a letter used 3 times. Could I use the lastIndexOf and the indexOf to tell the user what position their letter is in?Ouch. Are you considering doing that all the way to virtual infinity? Why not just show something like:
    "The letter you guessed is in position " + (indexHolder + 1)
    instead of converting numbers into english ordinal words. Unless you want to build that complexity into the system as well, for virtually no benefit.
    Also, what if the letter isn't found, when indexHolder is -1? You should account for that as well.

  • Random email generation

    i need the source code of random email generation.

    Can explain How you want the random email , or you want any unrepeated emails?

  • True Random number generation in OSX

    Hi there,
    I have been trying to find some information on how to access the Intel Random number generation hardware on my Mac.
    First I would like to understand which models currently offer this, second I would like to know if there is some library available I could use from either C or any other language, even from Applescript would be good for me.
    Thanks in advance.

    Perhaps these links help:
    http://www.intel.com/software/products/mkl/docs/mklnotes_mac.htm
    (keep in mind that apple typically discourages targeting specific hardware...)
    http://forums.macosxhints.com/showthread.php?t=46359
    http://www.mactricksandtips.com/2008/03/apple-script-random-number-generator.htm l

  • Random integer?

    Is this a correct way to generate a random integer between 1 and 6 ??? (1 and 6 included)
    private static int RandomEye()
      int r = 0;
      while (r < 1 || r > 6)
          Random r1 = new Random();
          r = Math.abs((r1.nextInt() % 6));
      return r;
    }And do I really need this while loop?

    Try this :
    private static int RandomEye()
    int r = 0;
    Random r1 = new Random();
    r = r1.nextInt(6) + 1;
    return r;
    You must put +1 because newtInt(6) return an integer between 0 and 5.
    Steve

  • What is the range of an Airport Express 2nd generation? The range is better than the 1st generation?

    What is the range of an Airport Express 2nd generation? The range is better than the 1st generation?

    150 feet in clear space with no obstructions in the signal path.  It is not possible to predict range with any obstructions in the signal path.

  • How to generate random integer?

    What is the func to generate random integer (at most 4-5 digits). Thanks.

    Luckily you asked an amazingly popular question - just take a peek at the answers found in this very forum:
    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=Generate+Random+Integer

  • Problem with random number generation

    hey forum, i wonder if anyone can help me out with a small problem with my university coursework (yep its homework!!!)
    heres my problem, i am writing one of them 8 puzzle problems (the one based around sam lloyds 15 puzzler), i can successfully generate one random sequence of numbers with no duplicates, but whenever i call the random method again it keeps producing the same results
    heres the code
    in my main class file
    if(e.getSource() == randomButton) {
          new RandomPuzzle();
          System.out.println(random.randState);
          //startStateString = new RandomPuzzle();
    }heres my number generator class file
    import java.util.Random;
    import java.io.*;
    public class RandomPuzzle
         /** Base Random number generator */
        Random rn = new Random();
        /** Puzzle holder */
        byte b[];
        long number = 0;
        String randState = "";
        /** Default constructor */
        public RandomPuzzle() {
            rn.setSeed(number);
            b = new byte[9];
            randState = randomString();
        /** Provide range for generation */
        public int rand(int lo, int hi) {
            int n = hi - lo + 1;
            int i = rn.nextInt() % n;
            if (i < 0)
            i = -i;
            return lo + i;
        /** Set size for array */
        public int rand( int hi){
            int n = hi;
                return n;
        /** Check for duplicate values within the same configuration */
        boolean valueExists( byte value ) {
            int i = b.length;
            boolean exists = false;
            for( int j = 0; j < i; j++ ){
                if( b[j] == value )
                    exists = true;
            return exists;
        /** returns the actual string */
        public String randomString(int lo, int hi) {
            int n = rand( 9 );
            //boolean valueEntered = false;
            for (int i = 0; i < 9; i++) {
                boolean valueEntered = false;
                byte temp = (byte)rand('0', '8');
                while( valueEntered == false ) {
                    if( !valueExists( temp ) ) {
                         b[i] = temp;
                         valueEntered = true;
                    else
                        temp = (byte)rand('0', '8');
            return new String(b, 0);
        /** calls above function */
        public String randomString() {
            return randomString(0, 8);
    }i've tried for hours to work this out, but i am stumped. if anyone can point me in the right direction, maybe point out the problem code and give one or two tips i would be forever in your debt
    thanx in advance
    korbitz

    thanx for the help paulcw, but when i removed the seed code it done the same
    but i added this to my main class and now it works fine
    if(e.getSource() == randomButton) {
                   RandomPuzzle temp = new RandomPuzzle();
                   System.out.println(temp.randState);
                   //startStateString = new RandomPuzzle();
              }thanx again for your help

  • Random Number Generation

    According to the documentation, java makes random numbers with this algorithm.
    synchronized protected int next(int bits) {
           seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
           return (int)(seed >>> (48 - bits));
    }The purely mathematical concept is this:
    Xn = (Xn-1 * constant1  + constant2) % constant3.In other words, to find a new number, we multiply the old number with a constant, add it to another constant, and then do modulus constant3 on the sum.
    That's okay, it's the java-specific implementation im wondering a little about.
    I've also understood that you can replace (sum % constant3) with (sum % (constant3 -1)), if constant3 is a power of 2.
    But:
    1. The function returns an integer, but still, the seed is a long.
    Why? Is it to prevent (seed * 0x5DEECE66DL + 0xBL) from overflowing?
    If that's the case, wouldnt that mean this function DEPENDS on long being longer than an integer?
    2.Why do they choose exactly (1L << 48)) as modulus?
    (1L << 48) ) means we got a 1, and 48 zeroes behind it? So the modulus is a power of 2 ^ 48, using 49 bits? And then we just subtract 1 to get to use the &, instead of the % operator, for performance reasons?
    Doesent this mean that this function depends on a long being atleast 64bits?
    What's the function of the remaining bits? (since we're just using 48 / 49 bits, during the computation).
    Are they used as a "overflow-buffer"?
    Edited by: Drogin on Jun 28, 2009 5:33 PM
    Edited by: Drogin on Jun 28, 2009 5:33 PM

    Drogin wrote:
    1. The function returns an integer, but still, the seed is a long.
    Why? Is it to prevent (seed * 0x5DEECE66DL + 0xBL) from overflowing?I don't see how it would prevent it overflowing or why it would matter.
    If that's the case, wouldnt that mean this function DEPENDS on long being longer than an integer?A lot in java depends on the JLS being followed.
    2.Why do they choose exactly (1L << 48)) as modulus?
    (1L << 48) ) means we got a 1, and 48 zeroes behind it? Perhaps because this function will only generate up to 32-bit and 48-bits is more than enough.
    So the modulus is a power of 2 ^ 48, using 49 bits?No, the operation specificly limits the value to be 48-bits long.
    Doesent this mean that this function depends on a long being a tleast 64bits?At least 48-bits I imagine, but it is 64-bits and always will be.
    And then we just subtract 1 to get to use the &, instead of the % operator, for performance reasons?Perhaps, jvms are smarter than they were whent he code was written so you might not need to do this now.
    What's the function of the remaining bits? (since we're just using 48 / 49 bits, during the computation).They don't appear to be used.
    Are they used as a "overflow-buffer"?It wouldn't matter if this function overflowed, so I wouldn't think so.
    In my experience, often in simple operations like this, the bit in the middle of the number are the most random. i.e. they have slightly better statistical properties.
    It is likely that people played around with the three numbers in this equation until they got a random distribution they were happy with.

  • Random Number generation within BPEL

    I am trying to embed a java-exec and trying to generate random number using a code as follows:
    int ranNumber1 = (int)(Math.random()*1000000000000000.0);
    int ranNumber2 = (int)(Math.random()*1000000000000000.0);
    setVariableData("RanNumber1",new Integer(ranNumber1));
    setVariableData("RanNumber2",new Integer(ranNumber2));
    I always get the same value for ranNumber1 and for ranNumber2 and for every instance, the value seems to be the same.. Actually the value generated is 2147483647 always..
    Am I doing anything wrong? Can anyone clarify here, please...

    // construct a bigdecimal, exaclty lenght'd 10 digits
    BigDecimal z = new BigDecimal("10000000000");
    // multiply it randomly (random returns something between 0 and 1)
    z = z.multiply(new BigDecimal(Math.random()));
    // and use the rounding ..
    BigInteger big = z.toBigInteger();
    is one option, I guess not the nicest but working ..

  • Selecting Random Integer from int[]

    Hi,
    I have created an integer array. I have a for loop which will add values to the array if the condition is met. I then want to select one of the values in the array to use at random. Would anyone be able to help.
    Thanks
    Sohaib

    you have to use an ArrayList to add objects once an array is declared its items can not be change plus ArrayList is much more useful for this problem
    import the ArrayList class and the Random class with the statements
    import java.util.ArrayList;
    import java.util.Random;then you can create a new ArrayList and Random such as
    ArrayList <int> randomNumbers = new ArrayList <int> ();
    Random rnd = new Random();you can add new values at random with a method such as
    public ArrayList setRandomNumbers(){
    if (+condition+){
    randomNumbers.add(+index+, rnd.nextInt(+highest number desired plus one here+)
    }or if you want to assign a number instead of one at random use
    randomNumbers.add(+index+,+number+)then you can reference them at random using:
    randomNumbers.get(rnd.nextInt(number of elements -1));You can find more ArrayList methods at
    [java.util.ArrayList|http://java.sun.com/j2se/1.3/docs/api/java/util/ArrayList.html]
    Edited by: DJDJ on Apr 2, 2008 8:46 AM
    Edited by: DJDJ on Apr 2, 2008 8:47 AM

  • Need Random "Number" Generation

    Hi...
    Need an easy way to generate a random "number" from an ABAP program... that is a combination of numbers and alphabetic characters.
    Is there a Function Module I did not find?
    Currently using Function module 'QF05_RANDOM_INTEGER' but this only generates a number.
    Thanks for your insights !
    Dave...

    Hi,
    I wrote a little method to generate a random number between 1 and 100 (can be modified to allow bigger range of numbers).  The code is below...  It basically gets a timestamp into a field of type timestampl (note the letter L at the end of the type).  The method signature consists of a single returning parameter called RANDOM_NUMBER (type I).  After much testing, the random sequence of numbers is extremely varied (even without a seed).
    Since 'QF05_RANDOM_INTEGER' already exists, then my method is not needed here, but I thought I'd include it in this thread since the topic was brought up.
    Cheers,
    James G.
    METHOD GENERATE_RANDOM_NUMBER .
      DATA:
        delay_cnt     TYPE i,
        lc_ran_seed   TYPE p,
        lc_time       TYPE timestampl,
        ran_num       TYPE p DECIMALS 7.
    * Get the long time stamp (nano second level)
      GET TIME STAMP FIELD lc_time.
    * Get the decimal part of the time stamp and shift it so that only the
    * last decimal values are used (i.e. the smallest unit of time)
      ran_num = frac( lc_time ).
      ran_num = ran_num * 10000.
    * Perform a delay with a varying length of time so that the next time
    * stamp will be more "random" if the method is called multiple times
    * (e.g. if called in a do loop to generate many random numbers)
      delay_cnt = ran_num * 2.
      DO delay_cnt TIMES. ENDDO.
    * Get the decimal part of the shifted time stamp, multiply it by 100 to
    * shift it to the left 2 decimal places, and add 1 to the result.
      ran_num = frac( ran_num ).
      lc_ran_seed = ( ran_num * 100 ) + 1.
      random_number = lc_ran_seed.
    * If the number generated is not between 1 and 100, then try again.
      IF random_number IS INITIAL OR random_number < 1
                                  OR random_number > 100.
        CALL METHOD me->generate_random_number
          RECEIVING
            random_number = random_number.
      ENDIF.
    ENDMETHOD.

Maybe you are looking for

  • Pavilion dv6-3130tx Blue Screen (BSOD) on adding RAM to second slot

    Hi there, I own a HP Pavilion dv6-3130tx with total of 3gb of RAM, one 1GB chip and one 2 GB chip. Recently I have been getting a lot of system crashes/freezes and occasional Blue Screen of Death (BSOD) with a variety of error messages. On contacting

  • Chart legend width in Firefox

    This may already be common knowledge, but we just bumped into what may be the cause of truncated chart legends in Firefox. I have been trying to figure out how to expand the width of the legend box that accompanies charts. Firefox sometimes renders t

  • Why do accepted meeting notifications stay in my iphone 4s inbox?

    The meetings are there - I just cant get rid of them out of my calendar inbox. It says "OK" as the only option (not Accept, Decline or Tentative), but when I hit OK, it flashes nicely... then remains. Help!?

  • ALV Reports versus ABAP drilldown or high volume data

    Which is better with regards to performance? An ALV grid or an ABAP drilldown ? I am very concerned about performance given the high volume of data and therefore not sure if I should use ALV? input is appreciated J

  • Converted from full memberrship to single app

    Adobe sent me an e-mail and told me I could change my full membership in Creative Cloud to a single membership. I did so, but I assumed the sinle membership would activate as of November since my account was charged for a full CC membership on Octobe