Click here to Skip to main content

Algorithms

    RSS: RSS Feed

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
AnswerSuch Equations Don't Exist PinmemberSom Shekhar8:42 15 Dec '09  
QuestionAdvice about choice of algorithm Pinmemberthebiggestbangtheory12:06 25 Nov '09  
AnswerRe: Advice about choice of algorithm PinmemberFatbuddha 122:02 26 Nov '09  
AnswerRe: Advice about choice of algorithm PinmemberEddy Vluggen1:28 27 Nov '09  
AnswerRe: Advice about choice of algorithm PinmemberAlan Balkany5:17 1 Dec '09  
QuestionHow to Generate Unique Serial Number.. Pinmembershaina22311:12 20 Nov '09  
AnswerRe: How to Generate Unique Serial Number.. PinmemberPaulo Zemek2:16 20 Nov '09  
They need to have an order or they must be "random"?
They have a size limit?
 
One of the possible solutions is to use GUID.
 
When GUID is not possible, I generally use a long value, that is get with DateTime.Ticks.Now (or incremented randomically) if both calls are in the same microsecond.
 
The class code follows, but you only need to call:
TicksOrIncrement.GetValue() to use it.
 
using System;
 
namespace Pfz.Threading
{
  /// <summary>
  /// Class that returns the value of DateTime.Now.Ticks when GetValue is called 
  /// but also guarantees that two calls will generate different values, even if
  /// they are done one just after the other.
  /// </summary>
  public static class TicksOrIncrement
  {
    private static readonly object fLock = new object();
    private static long fLastValue = DateTime.Now.Ticks;
    private static readonly Random fRandom = new Random();
		
    /// <summary>
    /// Gets a new DateTime.Now.Ticks value or a random incremented value if
    /// this is a call done at the same microsecond of the last one.
    /// </summary>
    public static long GetNext()
    {
      long ticks = DateTime.Now.Ticks;
			
      lock(fLock)
      {
        if (ticks <= fLastValue)
          ticks = fLastValue + 1 + fRandom.Next(1000);
				
        fLastValue = ticks;
      }
			
      return ticks;
    }
  }
}

GeneralRe: How to Generate Unique Serial Number.. Pinmembershaina22313:40 20 Nov '09  
GeneralRe: How to Generate Unique Serial Number.. PinmemberMember 419459312:44 11 Dec '09  
AnswerRe: How to Generate Unique Serial Number.. PinmemberRobin_Roy20:04 2 Dec '09  
GeneralRe: How to Generate Unique Serial Number.. Pinmembersupercat99:04 8 Dec '09  
QuestionWhats the fastest way to search through a binary heap? PinmemberCaptainSeeSharp19:08 18 Nov '09  
AnswerRe: Whats the fastest way to search through a binary heap? Pinmemberharold aptroot0:06 19 Nov '09  
GeneralRe: Whats the fastest way to search through a binary heap? PinmemberCaptainSeeSharp6:43 19 Nov '09  
GeneralRe: Whats the fastest way to search through a binary heap? Pinmemberharold aptroot7:00 19 Nov '09  
GeneralRe: Whats the fastest way to search through a binary heap? PinmemberCaptainSeeSharp7:07 19 Nov '09  
GeneralRe: Whats the fastest way to search through a binary heap? Pinmemberharold aptroot7:25 19 Nov '09  
GeneralRe: Whats the fastest way to search through a binary heap? PinmemberCaptainSeeSharp8:17 19 Nov '09  
QuestionCrowd detection (people), how to? PinmemberGamma_ace16:53 12 Nov '09  
AnswerRe: Crowd detection (people), how to? Pinmemberkaushik_acharya21:03 5 Nov '11  
QuestionAlgorithm to C# [modified] PinmemberVS newbie8:05 11 Nov '09  
AnswerRe: Algorithm to C# PinmemberRichardM112:29 11 Nov '09  
QuestionCollision Detection with a Quad tree PinmemberSK Genius17:22 5 Nov '09  
AnswerRe: Collision Detection with a Quad tree PinmvpLuc Pattyn17:40 5 Nov '09  
AnswerRe: Collision Detection with a Quad tree Pinmemberely_bob13:05 18 Nov '09  

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

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


Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 14 Feb 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid