8 Digit random number

  • Hello I am needing to find out how to do an 8 digit random number in
    cocoa.
    If there are no way than I can use random number from 10000000 to
    99999999 in applescript and receive the retuned value.
  • On May 7, 2008, at 1:50 PM, Mr. Gecko wrote:

    > Hello I am needing to find out how to do an 8 digit random number in
    > cocoa.
    > If there are no way than I can use random number from 10000000 to
    > 99999999 in applescript and receive the retuned value.

    Use rand()?

    --
    Seth Willits
  • On Wed, May 7, 2008 at 1:50 PM, Mr. Gecko <grmrgecko...> wrote:
    > Hello I am needing to find out how to do an 8 digit random number in cocoa.
    > If there are no way than I can use random number from 10000000 to 99999999
    > in applescript and receive the retuned value.

    <http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/ran
    dom.3.html
    >

    All you need to do is clamp/wrap the value get back to the number
    range you want.

    -Shawn
  • My knee jerk response was:
    (rand() % 90000000) + 10000000

    I like "clamp/wrap" better though :-)

    2008/5/7 Seth Willits <seth...>:

    > On May 7, 2008, at 1:50 PM, Mr. Gecko wrote:
    >
    > Hello I am needing to find out how to do an 8 digit random number in
    >> cocoa.
    >> If there are no way than I can use random number from 10000000 to
    >> 99999999 in applescript and receive the retuned value.
    >>
    >
    > Use rand()?
    >
    >
    > --
    > Seth Willits
    >
  • Le 7 mai 08 à 22:54, Seth Willits a écrit :
    > On May 7, 2008, at 1:50 PM, Mr. Gecko wrote:
    >
    >> Hello I am needing to find out how to do an 8 digit random number
    >> in cocoa.
    >> If there are no way than I can use random number from 10000000 to
    >> 99999999 in applescript and receive the retuned value.
    >
    > Use rand()?

    You probably mean random(3).

    long value = random() % 10000000;
  • I'll try
    On May 7, 2008, at 4:02 PM, Jean-Daniel Dupas wrote:

    > long value = random() % 10000000;
  • On May 7, 2008, at 2:02 PM, Jean-Daniel Dupas wrote:

    > Le 7 mai 08 à 22:54, Seth Willits a écrit :
    >> On May 7, 2008, at 1:50 PM, Mr. Gecko wrote:
    >>
    >>> Hello I am needing to find out how to do an 8 digit random number
    >>> in cocoa.
    >>> If there are no way than I can use random number from 10000000 to
    >>> 99999999 in applescript and receive the retuned value.
    >>
    >> Use rand()?
    >
    >
    > You probably mean random(3).
    >
    > long value = random() % 10000000;

    I do now. I didn't know about random(). **blush**

    In my defense, I rarely ever need to use a random number. :)

    --
    Seth Willits
  • Thanks That worked grate
    On May 7, 2008, at 4:17 PM, Jean-Daniel Dupas wrote:

    >
    > call srandomdev() before the first call to change the initial state.
    >
    > see man random for all details.
    >
    > Le 7 mai 08 à 23:10, Mr. Gecko a écrit :
    >> that is not really random maybe if I had added unix time stamp
    >> inside of random() how would I get that?
    >> On May 7, 2008, at 4:02 PM, Jean-Daniel Dupas wrote:
    >>
    >>> long value = random() % 10000000;
    >>
    >>
  • Yeah I knew that before in the days that I made c programs but it been
    so long that I forgot.

    On May 8, 2008, at 6:57 AM, Gregory Weston wrote:

    > Since neither the question nor the answer is particularly Cocoa-
    > related, I'm following up off-list. I just wanted to make sure that
    > you understood that using % to scale your raw result into the range
    > you want messes with the uniformity of the sequence. Consider, as a
    > degenerate case, that you had a random number generator that gave
    > you back a number from 0 to 15 and you wanted a number between 0 and
    > 11. If you did RND % 12, 0-3 will show up twice as often as any
    > other result. The closer the range of the random function is to an
    > integer multiple of the range you actually want, the less absolute
    > impact that has but there will almost always be some skewing
    > introduced. To alleviate that, you want to scale the raw result to a
    > number in [0,1), multiply that by the range of your desired result
    > and then add your minimum.
previous month may 2008 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Go to today