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 6327673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:19:18+00:00 2026-05-24T17:19:18+00:00

I am attempting to generate an array of random numbers in Mathematica in a

  • 0

I am attempting to generate an array of random numbers in Mathematica in a functional manner. This is my current attempt so far:

Array[Random[Real, {-10, 10}], 7]

The problem is that this is printing always the same number, which, of course, is not what I am looking for. I do understand that Mathematica is evaluating Random[Real, {-10,10}] once and then using always the same value. How can I circumvent the problem, keeping this functional style?

Thanks

  • 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-24T17:19:21+00:00Added an answer on May 24, 2026 at 5:19 pm

    The first argument to Array is intended to be a function which is applied to each array index (in this case, the values 1 through 7). If you evaluate

    Array[Random[Real, {-10, 10}], 7]
    

    The result is something like this:

    {3.91766[1], 3.91766[2], 3.91766[3], 3.91766[4], 3.91766[5], 
     3.91766[6], 3.91766[7]}
    

    What has happened is this:

    1. Random[Real, {-10, 10}] is evaluated producting 3.91766.
    2. This result is used as a “function” and is applied to each array index.

    Thus we see a list of expressions like 3.91766[1], an odd expression where a real number is being applied like a function to an integer.

    If the intent is generate a list of 7 different random numbers, one could use:

    Array[Random[Real, {-10, 10}] &, 7]
    

    The only difference between this and the original expression is the presence of ‘&’. This makes the first argument a function. The function is applied to each array index (but ignores it), and then returns a new random number each time.

    An alternative way to obtain this result uses Table:

    Table[Random[Real, {-10, 10}], {7}]
    

    In current versions of Mathematica, the Random function is obsolete and has been replaced by RandomInteger and RandomReal. In this case, RandomReal is useful:

    RandomReal[{-10, 10}, 7]
    

    … where the first argument is the range to choose from and the second argument is the number of desired values. Note that higher dimensional random arrays can also be generated, e.g.

    RandomReal[{-10, 10}, {7, 7}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to generate a random numbers with a logarithmic distribution. Where n=1
I am attempting to generate datamatrix barcodes from within itext. This works fine for
I am attempting to generate a BitmapFrame that is based on a UIElement .
I am attempting to generate an Expression tree that ultimately calls a series of
I'm attempting to simplify my code with a function that generates an array of
I'm attempting to generate an SVN log file through TortoiseSVN, if that is even
I am attempting to generate map overlay images that would assist in identifying hot-spots,
I am attempting to generate a multi-dimensional array with each sub array representing a
I am attempting to generate a weekly email to users of my site that
I am attempting to generate an ADO RecordSet programmatically within .Net. This will be

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.