Generate a positive number based on the current date's hash. - CSharp System

CSharp examples for System:Math Number

Description

Generate a positive number based on the current date's hash.

Demo Code

/* *******************************************************************************
 * Copyright (c) 2005-2012 Zibler S de RL MI.
 * //w w  w . j  av a2  s  . c  o m
 * This file is part of Zibler.
 * 
 * Zibler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Zibler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Zibler.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * *******************************************************************************/
using System.Threading;
using System.Text;
using System.Security.Cryptography;
using System;

public class Main{
        /// <summary>
        /// Generate a positive number based on the current date's hash.
        /// This number can be potentially used as an unique number, as
        /// long as there is at least 1 millisecond between calls.
        /// </summary>
        /// <returns>Positive Integer number</returns>
        public static int GetPositiveDateHash ()
        {
            int hash = DateTime.Now.GetHashCode ();
            
            /* Make it a positive number */
            if (hash < 0)
                hash = hash * -1;

            return hash;
        }
}

Related Tutorials