Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 825079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:11:49+00:00 2026-05-15T03:11:49+00:00

How can I use randomize and rnd to get a repeating list of random

  • 0

How can I use randomize and rnd to get a repeating list of random variables?

By repeating list, I mean if you run a loop to get 10 random numbers, each random number in the list will be unique. In addition, if you were to run this sequence again, you would get the same 10 random numbers as before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:11:49+00:00Added an answer on May 15, 2026 at 3:11 am

    From Microsoft’s own mouth:

    To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument.

    See here for details.

    The whole section:


    Remarks

    The Rnd function returns a value less than 1 but greater than or equal to zero.

    The value of number determines how Rnd generates a random number:

    For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.

    Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

    To produce random integers in a given range, use this formula:

    Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    

    Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.

    Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.


    By way of example, if you put this code into Excel, it generates a different number each time you run it:

    Sub xx()
        ' x = Rnd(-1) '
        Randomize 10
        MsgBox (Rnd)
    End Sub
    

    However, if you uncomment the x = Rnd(-1) line, it generates the same number on each run.

    Note that you have to do two things. Call Rnd with a negative argument and call Randomize with a specific argument. Changing either of those things will give you a different seed (and therefore sequence).


    Edit:

    Re your comment:

    By repeating sequence, I mean if you run a loop to get 10 random numbers, each random number in the list will be unique. In addition, if you were to run this sequence again, you would get the same 10 random numbers as before. Does what I’m describing make sense?

    You now need one more piece of information. What you’re asking for is not random numbers but a shuffling algorithm. I’ll refer you to an earlier answer I gave on how to do this here. All you need to do is combine the shuffling algorithm with the seed-setting detailed above and you’ll have your repeatable, unique sequence.


    And here’s some code that shows it in action. Every run of this subroutine returns the sequence 4 1 5 6 2 3 7 10 9 8 so I think that’s what you were after, a repetable, “random”, unique sequence. If you wanted to be able to generate different sequences (but still in a repeatable manner), you only need to change the value given to Randomize.

    Option Explicit
    Option Base 1
    
    Sub xx()
        Dim x(10) As Integer
        Dim xc As Integer
        Dim xp As Integer
        Dim i As Integer
        Dim s As String
    
        For i = 1 To 10
            x(i) = i
        Next
        xc = 10
    
        i = Rnd(-1)
        Randomize 1
    
        s = "Values:"
        For i = 1 To 10
            xp = Int(Rnd * xc) + 1
            s = s & " " & CStr(x(xp))
            x(xp) = x(xc)
            xc = xc - 1
        Next i
    
        MsgBox (s)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We can use either count(<column_name>) or system tables to get the number of rows
I can use ipcs(1) to list out the active shared memory objects on a
I can use File('foo.bar').abspath to get the location of a file, but if I've
How can use the key argument for the min function to compare a list
I am trying to use F# to generate a list of random triples ->
I can use FireFox and FireBug, in a pane, I can open a .css
I can use the PRINT statement in a stored procedure to debug my code.
I can use stat() to figure out what permissions the owner, group, or others
We can use solr range query like: http://localhost:8983/solr/select?q=queryStr&fq=x:[10 TO 100] AND y:[20 TO 300]
You can use the Filter property of a BindingSource to do SQL like filtering.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.