Professional Web Applications Themes

RAND() generating same number in rapid sequence - MySQL

I am using RAND() in rapid sequence, possibly on different connections. I expected to get different numbers from RAND(). I didn't. I get the same number within a given timeframe - it's like it's driven entirely by microtime. Am I stuck? I need different numbers for images. The only solution I can think of is to get 'the next image' from the database. to make it look random. but that's not very random. any ideas?...

  1. #1

    Default RAND() generating same number in rapid sequence

    I am using RAND() in rapid sequence, possibly on different connections.
    I expected to get different numbers from RAND(). I didn't. I get the same
    number within a given timeframe - it's like it's driven entirely by
    microtime.
    Am I stuck?

    I need different numbers for images. The only solution I can think of is to
    get 'the next image' from the database. to make it look random. but that's
    not very random.

    any ideas?


    Jim Michaels Guest

  2. #2

    Default Re: RAND() generating same number in rapid sequence


    "Peter H. Coffin" <hellsopninehells.com> wrote in message
    news:slrne4m0fr.mnd.hellsopothin.ninehells.com...
    > On Sat, 22 Apr 2006 18:47:49 -0700, Jim Michaels wrote:
    >> I am using RAND() in rapid sequence, possibly on different
    >> connections. I expected to get different numbers from RAND(). I
    >> didn't. I get the same number within a given timeframe - it's like
    >> it's driven entirely by microtime. Am I stuck?
    >>
    >> I need different numbers for images. The only solution I can think of
    >> is to get 'the next image' from the database. to make it look random.
    >> but that's not very random.
    >>
    >> any ideas?
    >
    > Generate your random number on the application level? Use an
    tried that. same problem. no solution yet. microsecond resolution of
    uniqid() isn't fast enough to give me random images. this must be cached in
    memory at the server or something.
    > autoincrement column instead of a random one? Start with telling us what
    > problem you're trying to solve rather than telling us your not-working
    Trying to generate multiple random images by a onsie-script that selects one
    hopefully unique image (from an existing table of images that has id
    numbers) on a web page. At the very least, they should be different images
    from each other, so they *could* be sequential if I can't get random to
    work.
    > solution. That is, "I want to have a unique file name I can give to an
    > image associated with information stored in a table" instead of "RAND()
    > isn't random enough, so I can't make a file name out of it and guarantee
    > uniqueness".
    >

    Jim Michaels Guest

  3. #3

    Default Re: RAND() generating same number in rapid sequence


    "Jim Michaels" <NOSPAMFORjmichae3> wrote in message
    news:fKKdnXFcNOVJsNHZnZ2dnUVZ_uWdnZ2dcomcast.com. ..
    >
    > "Peter H. Coffin" <hellsopninehells.com> wrote in message
    > news:slrne4m0fr.mnd.hellsopothin.ninehells.com...
    >> On Sat, 22 Apr 2006 18:47:49 -0700, Jim Michaels wrote:
    >>> I am using RAND() in rapid sequence, possibly on different
    >>> connections. I expected to get different numbers from RAND(). I
    >>> didn't. I get the same number within a given timeframe - it's like
    >>> it's driven entirely by microtime. Am I stuck?
    >>>
    >>> I need different numbers for images. The only solution I can think of
    >>> is to get 'the next image' from the database. to make it look random.
    >>> but that's not very random.
    >>>
    >>> any ideas?
    >>
    >> Generate your random number on the application level? Use an
    >
    > tried that. same problem. no solution yet. microsecond resolution of
    > uniqid() isn't fast enough to give me random images. this must be cached
    > in memory at the server or something.
    >
    >> autoincrement column instead of a random one? Start with telling us what
    >> problem you're trying to solve rather than telling us your not-working
    >
    > Trying to generate multiple random images by a onsie-script that selects
    > one hopefully unique image (from an existing table of images that has id
    > numbers) on a web page. At the very least, they should be different
    > images from each other, so they *could* be sequential if I can't get
    > random to work.
    >
    >> solution. That is, "I want to have a unique file name I can give to an
    >> image associated with information stored in a table" instead of "RAND()
    >> isn't random enough, so I can't make a file name out of it and guarantee
    >> uniqueness".
    >>
    >
    >

    found the solution. the browser was cacheing the image and therefore giving
    me duplicates. the random number generator in the DB is fine. I don't have a
    "microtime" problem with it. All my thinking was bogus. I've been wrong
    before.


    Jim Michaels Guest

Similar Threads

  1. good rapid development tool
    By Henk Verhoeven in forum PHP Development
    Replies: 0
    Last Post: April 2nd, 12:07 AM
  2. Sequence Number Generator in IDS 9.4
    By Cindy Lichtenauer in forum Informix
    Replies: 5
    Last Post: October 15th, 11:14 PM
  3. Replies: 2
    Last Post: July 9th, 10:17 AM
  4. Replies: 0
    Last Post: July 9th, 06:28 AM
  5. sequence number in a view
    By Aaron Bertrand - MVP in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 3rd, 04:21 PM

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
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139