CSharp examples for System:Math Number
generate a pseudo unique 9 digit number. It uses the System.DateTime.Now.Ticks as the base for its calculations.
/* ******************************************************************************* * Copyright (c) 2005-2012 Zibler S de RL MI. * //ww w.j av a 2 s .co 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> /// This method will generate a pseudo unique /// 9 digit number. It uses the System.DateTime.Now.Ticks /// as the base for its calculations. /// </summary> /// <remarks>Note that if this function is called twice very fast, in /// such a way that the Ticks value has not changed, then it will return /// the same generated number twice. /// /// This function will provide about 963946 different Ids a day. This number could /// be less</remarks> /// <returns>Pseudo Unique number</returns> public static int GeneratePseudoUniqueNumber () { string stringNumber = String.Format ("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); int result = Convert.ToInt32 (stringNumber); return result; } }