Click here to Skip to main content
15,889,861 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Solving a circularly recursive system of equations Pin
mabo429-Dec-09 4:05
mabo429-Dec-09 4:05 
AnswerSuch Equations Don't Exist Pin
Som Shekhar15-Dec-09 7:42
Som Shekhar15-Dec-09 7:42 
QuestionAdvice about choice of algorithm Pin
thebiggestbangtheory25-Nov-09 11:06
thebiggestbangtheory25-Nov-09 11:06 
AnswerRe: Advice about choice of algorithm Pin
Fatbuddha 126-Nov-09 21:02
Fatbuddha 126-Nov-09 21:02 
AnswerRe: Advice about choice of algorithm Pin
Eddy Vluggen27-Nov-09 0:28
professionalEddy Vluggen27-Nov-09 0:28 
AnswerRe: Advice about choice of algorithm Pin
Alan Balkany1-Dec-09 4:17
Alan Balkany1-Dec-09 4:17 
QuestionHow to Generate Unique Serial Number.. Pin
shaina223120-Nov-09 0:12
shaina223120-Nov-09 0:12 
AnswerRe: How to Generate Unique Serial Number.. Pin
Paulo Zemek20-Nov-09 1:16
mvaPaulo Zemek20-Nov-09 1:16 
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.

C#
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.. Pin
shaina223120-Nov-09 2:40
shaina223120-Nov-09 2:40 
GeneralRe: How to Generate Unique Serial Number.. Pin
Member 419459311-Dec-09 11:44
Member 419459311-Dec-09 11:44 
AnswerRe: How to Generate Unique Serial Number.. Pin
Robin_Roy2-Dec-09 19:04
Robin_Roy2-Dec-09 19:04 
GeneralRe: How to Generate Unique Serial Number.. Pin
supercat98-Dec-09 8:04
supercat98-Dec-09 8:04 
QuestionWhats the fastest way to search through a binary heap? Pin
CaptainSeeSharp18-Nov-09 18:08
CaptainSeeSharp18-Nov-09 18:08 
AnswerRe: Whats the fastest way to search through a binary heap? Pin
harold aptroot18-Nov-09 23:06
harold aptroot18-Nov-09 23:06 
GeneralRe: Whats the fastest way to search through a binary heap? Pin
CaptainSeeSharp19-Nov-09 5:43
CaptainSeeSharp19-Nov-09 5:43 
GeneralRe: Whats the fastest way to search through a binary heap? Pin
harold aptroot19-Nov-09 6:00
harold aptroot19-Nov-09 6:00 
GeneralRe: Whats the fastest way to search through a binary heap? Pin
CaptainSeeSharp19-Nov-09 6:07
CaptainSeeSharp19-Nov-09 6:07 
GeneralRe: Whats the fastest way to search through a binary heap? Pin
harold aptroot19-Nov-09 6:25
harold aptroot19-Nov-09 6:25 
GeneralRe: Whats the fastest way to search through a binary heap? Pin
CaptainSeeSharp19-Nov-09 7:17
CaptainSeeSharp19-Nov-09 7:17 
QuestionCrowd detection (people), how to? Pin
Gamma_ace12-Nov-09 15:53
Gamma_ace12-Nov-09 15:53 
AnswerRe: Crowd detection (people), how to? Pin
kaushik_acharya5-Nov-11 20:03
kaushik_acharya5-Nov-11 20:03 
QuestionAlgorithm to C# [modified] Pin
VS newbie 11-Nov-09 7:05
VS newbie 11-Nov-09 7:05 
AnswerRe: Algorithm to C# Pin
RichardM111-Nov-09 11:29
RichardM111-Nov-09 11:29 
QuestionCollision Detection with a Quad tree Pin
Anthony Mushrow5-Nov-09 16:22
professionalAnthony Mushrow5-Nov-09 16:22 
AnswerRe: Collision Detection with a Quad tree Pin
Luc Pattyn5-Nov-09 16:40
sitebuilderLuc Pattyn5-Nov-09 16:40 

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.