Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-187

Performance improvements for an array shuffle

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Implemented
    • 1.6
    • 1.7
    • sampling
    • None
    • Easy

    Description

      Improve the performance of array shuffling by generation of multiple indices in a range [0, n) from a single sample from a random source.

      The current UniformRandomProvider method to sample an integer in a range [0, n) uses a rejection method based on multiplication with a single use of a slow modulus operator if rejection is required. The author of that method has extended it to allow generation of multiple integers from 2 or more ranges from the same random sample.

      When applied to a shuffle algorithm the speed-up can be significant, typically in the range of up to 2-fold for smaller arrays depending on the speed of the random generator; slower generators see a greater speed-up.

      The method is described in:

      Nevin Brackett-Rozinsky, Daniel Lemire,
      Batched Ranged Random Integer Generation,
      Software: Practice and Experience (to appear)
      

      See arXiv:2408.06213M.

      See also Daniel Lemire Blog: Faster random integer generation with batching

       

      Attachments

        1. shuffle.png
          163 kB
          Alex Herbert
        2. shuffle-1.png
          170 kB
          Alex Herbert
        3. shuffle34.png
          322 kB
          Alex Herbert

        Activity

          People

            Unassigned Unassigned
            aherbert Alex Herbert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: