Results 1 to 5 of 5
  1. #1
    gmontano is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    9

    Query Random Number Column Manipulation

    I have a query and have the following expression in a column of the query which generates a random number for each record in the query:



    Random: Rnd([WorkID])


    Is there a way I can manipulate this so that the random number is a whole number with the max number being the total amount of records the query returned?

    Below, you can see a possible outcome. If there were 8 records returned in the query, the random numbers would be 1-8, but in no particular order. Although, the random numbers would need to be unique to the others.

    WorkID Random
    65 5
    35 1
    34 3
    56 4
    85 2


    I have seen this bit of code:

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

    I was wondering if you can set the upper to the count of your records and make the results unique some how.

    Thank you for your help.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    you can not get a unique sequent number using RND. if you run RND 100 times and convert it within 1 - 100, 99.99% of chance you get at least one pair of duplicate numbers.

  3. #3
    gmontano is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    9
    Thank you, Weekend00.

    I was afraid of that.

    I appreciate you taking the time to help me.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    g,

    weekend is right for sure, but you can do this in other ways. but using the RND() function for an uppbound of the query's dataset inside the sql statement, NO you can't.

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    put the numbers 1-8 in an array. use rnd. delete the picked number from the array. loop.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. pulling text values into FK number column
    By REBBROWN in forum Database Design
    Replies: 2
    Last Post: 08-30-2010, 05:04 PM
  2. Sorta Random Serial Number Generator
    By Cuselco in forum Programming
    Replies: 3
    Last Post: 08-27-2010, 12:05 PM
  3. Replies: 7
    Last Post: 04-27-2010, 02:47 PM
  4. Random number generators with no repeats
    By CJ508 in forum Access
    Replies: 5
    Last Post: 10-29-2009, 07:30 AM
  5. Query manipulation using VBA
    By benattal in forum Programming
    Replies: 0
    Last Post: 12-31-2008, 09:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums