Click here to Skip to main content
15,891,951 members
Home / Discussions / C#
   

C#

 
QuestionCustom Controls And Events Pin
rich_wenger6-Dec-05 3:48
rich_wenger6-Dec-05 3:48 
QuestionAutoRedraw Pin
Sabry19056-Dec-05 2:47
Sabry19056-Dec-05 2:47 
Question.NET Remoting and recorded sound? Pin
mikker_1236-Dec-05 1:27
mikker_1236-Dec-05 1:27 
Questiondll Pin
ambedkar6-Dec-05 1:26
ambedkar6-Dec-05 1:26 
AnswerRe: dll Pin
Colin Angus Mackay6-Dec-05 1:51
Colin Angus Mackay6-Dec-05 1:51 
Questionalgorithm for 6 digits unique number Pin
Ronen Tidhar6-Dec-05 1:12
Ronen Tidhar6-Dec-05 1:12 
AnswerRe: algorithm for 6 digits unique number Pin
Colin Angus Mackay6-Dec-05 1:19
Colin Angus Mackay6-Dec-05 1:19 
AnswerRe: algorithm for 6 digits unique number Pin
J4amieC6-Dec-05 2:25
J4amieC6-Dec-05 2:25 
A quick check of the number of milliseconds in a day gives 86400000

TimeSpan ts = new TimeSpan(1,0,0,0,0);<br />
Console.WriteLine(ts.TotalMilliseconds);


So, first point you are not going to be able to generate a unique 6 digit number, that is millisecond different, based on the current millisecond in a given day.

Lets see how accurate it could be....

Max 6 digit number = 999999
Milliseconds in a day = 86400000
Spread = 86400000 / 999999 = 86.4ms (approx)

So every 86.4ms (thats 0.086 seconds) a new number would be generated, every call to generate a number within that timespan would create the same number.

Now, your choices

1) If your app will never make a call to generate this number as frequently as every 100ms, you are free to use the above solution. Just get the current number of miiliseconds since midnight, divide by (approx - do the math) 86.4, round to the nearest integer and you will have a 6 digit whole number.

2) If you DO actually need this accurate within 1ms (which i doubt) you can use a bigger number (Milliseconds is usually depicted as an int).
GeneralRe: algorithm for 6 digits unique number Pin
Ronen Tidhar7-Dec-05 1:07
Ronen Tidhar7-Dec-05 1:07 
GeneralRe: algorithm for 6 digits unique number Pin
Ronen Tidhar7-Dec-05 1:51
Ronen Tidhar7-Dec-05 1:51 
GeneralRe: algorithm for 6 digits unique number Pin
Dan Neely7-Dec-05 2:09
Dan Neely7-Dec-05 2:09 
GeneralRe: algorithm for 6 digits unique number Pin
Nick Hounsome8-Dec-05 22:40
Nick Hounsome8-Dec-05 22:40 
QuestionAre parameter arrays CLS compliant? Pin
Nish Nishant6-Dec-05 1:02
sitebuilderNish Nishant6-Dec-05 1:02 
AnswerRe: Are parameter arrays CLS compliant? Pin
S. Senthil Kumar6-Dec-05 1:22
S. Senthil Kumar6-Dec-05 1:22 
GeneralRe: Are parameter arrays CLS compliant? Pin
Nish Nishant6-Dec-05 2:32
sitebuilderNish Nishant6-Dec-05 2:32 
QuestionDataTime Pin
papa19806-Dec-05 0:55
papa19806-Dec-05 0:55 
AnswerRe: DataTime Pin
Colin Angus Mackay6-Dec-05 1:17
Colin Angus Mackay6-Dec-05 1:17 
GeneralRe: DataTime Pin
papa19806-Dec-05 1:23
papa19806-Dec-05 1:23 
GeneralRe: DataTime Pin
papa19806-Dec-05 1:27
papa19806-Dec-05 1:27 
GeneralRe: DataTime Pin
Colin Angus Mackay6-Dec-05 1:44
Colin Angus Mackay6-Dec-05 1:44 
GeneralRe: DataTime Pin
papa19806-Dec-05 1:56
papa19806-Dec-05 1:56 
GeneralRe: DataTime Pin
Colin Angus Mackay6-Dec-05 2:11
Colin Angus Mackay6-Dec-05 2:11 
GeneralRe: DataTime Pin
papa19806-Dec-05 3:48
papa19806-Dec-05 3:48 
AnswerRe: DataTime Pin
albCode14-Dec-05 5:07
albCode14-Dec-05 5:07 
QuestionLogin page Pin
ambedkar6-Dec-05 0:32
ambedkar6-Dec-05 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.