Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: random pieces of number

  1. #11
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: random pieces of number

    I don't think you can generate random numbers directly in Bash. You can use Python:

    Code:
    python -c "import random; print random.randint(1, n)"
    will give you a random number between 1 and n (inclusive).
    「明後日の夕方には帰ってるからね。」


  2. #12
    Join Date
    Jun 2010
    Location
    UK
    Beans
    206
    Distro
    Xubuntu 10.04 Lucid Lynx

    Re: random pieces of number

    It really depends on what you mean by random. Different algorithms will give different distributions and without knowing what you are using it for it is difficult to say of an approach "This will give the best results".

    Although the algorithm outlined by varies people above would be the simplest to implement, that of recursively choosing an integer between 1 and the remaining space left. It is a skewed distribution, ie, the first numbers are bigger in general.

    Another approach is to generate a number between 1 and the size. This is the amount of numbers you will generate. Set all of the numbers to one, then randomly increment them until the sum is equal to size. This will generate a distribution that is not skewed.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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