Will this give me a random number?

# Thread: Will this give me a random number?

1. Senior Member
Join Date
Dec 1969
Posts
817

## Will this give me a random number?

Empvar = Int ( rnd * 10000 )

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Only if...

...you use the RANDOMIZE statement *ONE TIME ONLY* someplace in the ASP page before you get to that line.<BR><BR>Then that will get you an integral number from 0 to 9999.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
6,476

## Question is

Will it generate a random number every time it&#039;s requested.<BR><BR>If you call that page 100 times<BR>what are the odds of getting duplicate values?

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Probably pretty fair...

&nbsp;<BR>Did you know that if you collect a roomful of about 30 people, unknown to each other, and ask them what their birthdays are, you have a slightly better than even chance of getting two people with the same birthday?<BR><BR>At first, you say "How can that be! There&#039;s 365 different days, so if you take 30 people, the odds should be 30 in 365 or roughtly 1 in 12."<BR><BR>Ahhh...but that would be true if you wanted to match *ONE PARTICULAR* person&#039;s birthday!<BR><BR>But since you can match *ANYBODY&#039;S* birthday, the odds are the sum of<BR>29/365 + 28/364 + 27/363 + .....<BR><BR>Or something like that. I forget the exact formula.<BR><BR>***********<BR><BR>So this situation is similar. Pick one random number. What are the odds that a pick in the next 100 will match it? Only 1 in 10,000. But that changes majorly when you can match any of the 100 against any other.<BR><BR>My gut feel says the odds should be around 20% or so that you&#039;ll find one duplicate.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: Probably pretty fair...

I had used this same thing a while back and did find there were a fair number of duplicates<BR>20% probably close to being right...<BR><BR>But I have seen it to come accross a duplicate within the 1st 4 or 5 tries...<BR><BR>This would be no good for what dan18088 wants it for...<BR>Its to generate unique ID values for (Only some) users...<BR>But still, any chance of a duplicate would mess that up for him.<BR>Wouldnt you think?<BR><BR>I know he didnt say that in his post, so you wouldnt have known about it.<BR>

6. Senior Member
Join Date
Dec 1969
Posts
6,476

## And it's a Text field

That holds all the ID numbers<BR>(From what I gathered)<BR><BR>A Temp ID will be random number<BR>When time comes a "/ChangedGiven" ID will be Letters followed by numbers.<BR><BR>Best I gathered from it all.<BR>

7. Senior Member
Join Date
Dec 1969
Posts
817

## But I could add the employee number.........

That submits the form and then add a random number to the end of that ID. So now I really doubt I would get a duplicate. <BR><BR>But I can&#039;t even get the random thing to work. Same EmpID for each row I add?<BR><BR>&#060;% Randomize<BR><BR> EmpVar = Int (rnd * 10000)<BR><BR>%&#062;<BR><BR><BR>&#060;th&#062;&#0 60;center&#062;&#060;b&#062;Enter Times/Commissions for any employee not listed&#060;/b&#062;&#060;/center&#062;&#060;/th&#062;<BR>&#060;table border=1 cellpadding=0 cellspacing=0"&#062;<BR><BR>&#060;form method="POST" form name="Exceptions" action="DoExceptions.asp"&#062;<BR>&#060;td width=250&#062;<BR>&#060;Select name="Exception" onChange="addRow()"&#062;<BR>&#060;option value=""&#062;&#060;/option&#062;<BR>&#060;option value="NewEmp"&#062;New Employee&#060;/option&#062;<BR>&#060;option value="TermedEmp"&#062;Terminated Employee&#060;/option&#062;<BR>&#060;/select&#062;<BR>&#060;input type="Hidden" name="EmployeeID" value="&#060;%=EmpVar%&#062;"&#062;<BR>&#060;td&#0 62;&#060;font size=-1 &#062;&#060;input name="Hours" size="9" value="&#060;%=Hours%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="Commission" size="9" value="&#060;%=Commission%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="PTO" size="9" value="&#060;%=PTO%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="OT" size="9" value="&#060;%=OT%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="DBL" size="9" value="&#060;%=DBL%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="OnCall" size="9" value="&#060;%=OnCall%&#062;"&#062;&#060;/TD&#062;<BR>&#060;td&#062;&#060;font size=-1 &#062;&#060;input name="PTODollars" size="9" value="&#060;%=PTODollars%&#062;"&#062;&#060;/TD&#062;<BR>&#060;/TR&#062;<BR><BR><BR>&#060;script&#062;<BR>var ELpntr=1;<BR>var content1=&#039;&#039;;<BR>var content2=&#039;&#060;input name="EmployeeID&#039;+ELpntr+&#039;" value="&#060;%=EmpVar%&#062;"&#062;&#039;;<BR>var content3=&#039;&#060;input size=9 name="Hours&#039;+ELpntr+&#039;"&#062;&#039;;<BR>v ar content4=&#039;&#060;input size=9 name="Commission&#039;+ELpntr+&#039;"&#062;&#039;; <BR>var content5=&#039;&#060;input size=9 name="PTO&#039;+ELpntr+&#039;"&#062;&#039;;<BR>var content6=&#039;&#060;input size=9 name="OT&#039;+ELpntr+&#039;"&#062;&#039;;<BR>var content7=&#039;&#060;input size=9 name="DBL&#039;+ELpntr+&#039;"&#062;&#039;;<BR>var content8=&#039;&#060;input size=9 name="OnCall&#039;+ELpntr+&#039;"&#062;&#039;;<BR> var content9=&#039;&#060;input size=9 name="PTODollars&#039;+ELpntr+&#039;"&#062;&#039;; <BR><BR><BR>function addRow(){<BR><BR><BR>ELpntr++;<BR>content1=&#039;& #060;select name="Exception&#039;+ELpntr+&#039;" onChange="addRow()"&#062;&#039;;<BR>content1+=&#03 9;&#060;option value"" selected&#062;&#060;/option&#062;&#039;;<BR>content1+=&#039;&#060;optio n value"NewEmp"&#062;New Employee&#060;/option&#062;&#039;;<BR>content1+=&#039;&#060;optio n value"TermedEmp"&#062;Terminated Employee&#060;/option&#062;&#060;/select&#062;&#039;;<BR>tabBody=document.getElement sByTagName("TBODY").item(0);<BR>row=document.creat eElement("TR");<BR>cell1 = document.createElement("TD");<BR>cell2 = document.createElement("TD");<BR>cell3 = document.createElement("TD");<BR>cell4 = document.createElement("TD");<BR>cell5 = document.createElement("TD");<BR>cell6 = document.createElement("TD");<BR>cell7 = document.createElement("TD");<BR>cell8 = document.createElement("TD");<BR>cell1.innerHTML=c ontent1;<BR>cell2.innerHTML=content2;<BR>cell3.inn erHTML=content3;<BR>cell4.innerHTML=content4;<BR>c ell5.innerHTML=content5;<BR>cell6.innerHTML=conten t6;<BR>cell7.innerHTML=content7;<BR>cell8.innerHTM L=content8;<BR>row.appendChild(cell1);<BR>row.appe ndChild(cell2);<BR>row.appendChild(cell3);<BR>row. appendChild(cell4);<BR>row.appendChild(cell5);<BR> row.appendChild(cell6);<BR>row.appendChild(cell7); <BR>row.appendChild(cell8);<BR>tabBody.appendChild (row);<BR><BR>}<BR><BR>function DoSubmit(){<BR> document.getElementById(&#039;TotalExceptions&#039 ;).value = ELpntr;<BR> document.forms[0].submit();<BR>}<BR>&#060;/script&#062;<BR>&#060;/table&#062;<BR>&#060;/Div&#062;<BR><BR>&#060;p align="center"&#062;<BR>&#060;input type="button" value="Submit" name="B1" onClick="DoSubmit();"&#062;&#060;input type="reset" value="Reset" name="B2"&#062;<BR>&#060;input type="hidden" value="" name="TotalExceptions" id="TotalExceptions"&#062;<BR>&#060;/p&#062;<BR>&#060;/Form&#062;<BR>&#060;/HTML&#062;<BR>

8. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: But I could add the employee number.........

Your not hitting the back button then submitting again are you?<BR><BR>Because it should be generating random numbers for the most part...<BR><BR>Question.<BR>Since the ID&#039;s are Letters and numbers<BR>There must be some method used to generate the numbers right?<BR>then letters are just added to front of it?<BR><BR>Can you not tap into that method just for the use of the numbers?<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
6,476

More than 1 record at a time?<BR><BR>Im no Java Script guy at all.<BR><BR>Are you generating the asp page<BR>then using JS to add more than 1 Row<BR>Then post the page to next page and insert it into the datbase??<BR><BR>If so then you need to generate the random number In Javascript<BR>And call for a new random number everytime you add a new row....<BR><BR>Asp will generate 1 random number and send it to the page.<BR>This is the only number you have to use in the browser.<BR><BR>Your using that same number many times in your JS<BR>That Random number is only generated on the Server.<BR>

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Well OF COURSE they're the same!

You only GENERATE one single random number for the entire page!!!!!<BR><BR>You use<BR> &#060;%=EmpVar%&#062;<BR>all over the place, but it&#039;s the SAME EmpVar that you created, one time, at the top of the page!<BR><BR>But you have 1000% COMPLETELY AND UTTERLY lost me!<BR><BR>Why in the world would you *EVER* want to assign a RANDOM number as the employeeid?????<BR><BR>

#### Posting Permissions

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