Random number based on Records

Results 1 to 5 of 5

Thread: Random number based on Records

  1. #1
    SHILA Guest

    Default Random number based on Records

    HI ,<BR>I would like to know hiowcan I use the Rnd function for selecting a random value from the rows of a field of a table.I mean<BR>If there is one field called &#039;id&#039; having values 1 to 40 consecutively... then how can I select values from this column randomly.<BR>Is there any way that the random values are not repeated.<BR>Can anybody help me with the codes.I am pasting a bit of the code showing How I am doing it....<BR>&#039;***** Open Database/Recordset<BR> Set DB = Server.CreateObject("ADODB.Connection")<BR> DB.Open "filedsn=superman.dsn"<BR> Set RS = Server.CreateObject("ADODB.Recordset")<BR> queryString = "SELECT * FROM employee"<BR> RS.Open queryString, DB,3,3<BR><BR> &#039;***** Get total record count<BR> TotalRec = RS.RecordCount<BR>&#039;***** Select random number based on total records // <BR> Randomize<BR> Selection = Int(TotalRec*rnd)+1<BR> response.write(Selection &"<BR>")...............<BR>Best Regards,<BR>SHILA

  2. #2
    Join Date
    Dec 1969

    Default Not Advanced

    see http://www.infinitemonkeys.ws/<BR><BR>I believe the source code is in the codelibrary section. "selecting a random record"<BR><BR>j

  3. #3
    Join Date
    Dec 1969

    Default ASPFAQs.com, FAQ # 65

    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=65<BR><BR>Happy Programming!

  4. #4
    SHILA Guest

    Default Thanks Atrax Thanks Scott

    Thanks! Atrax Thanks! Scott

  5. #5
    SHILA Guest

    Default HELP NEEDED AGAIN 'Rnd'

    Hi!,<BR><BR>Thanks to Atrax and Scott for helping me get started with my solution but one thing which I find funny is.....<BR>Say...I have a lottery system in which , there are around 75 prizes and the prizes are selected randomly from the record......I have one of the columns as Id the Id column sequentially increases from 1 to 75.So as and when one random number is generated using the &#039;Rnd&#039; function on the records of Id column...after &#039;Randomize&#039; one row is displayed and deleted and the next random number is generated from the remaining records.eg.. after first run the random number is generated from 74 records after second run it is generated from 73 rows and so on... but once it decreases to around 10 or lesser rows it gives sql...error....Why is it so.....? Its same for MS Access too....<BR>Is it same for all microsoft database products or is there any solution...maybe from ASP...?<BR><BR>Thanks & Regards,<BR>SHILA

Posting Permissions

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