MsgBox(Guid.NewGuid.ToString.Where(Function(n) Char.IsDigit(n)).ToArray)
|
.NET
How do I generate a random number? |
(Oct 5, 2014 02:02 PM)+Haze Wrote: Replace the Dim with "static" so the instance will only be initiated once the entire session of the application being runned. (Oct 6, 2014 02:51 PM)IAmNotHere Wrote: Hello TheBarret, http://msdn.microsoft.com/en-us/library/z2cty7t8.aspx (Oct 6, 2014 02:51 PM)IAmNotHere Wrote: Hello TheBarret, Well its quite easy, the static , name already gives you a clue what it does, the instance will be loaded once and keep its object, so in a shared or private method with the static Random object that is declared, will not be re-declared or re-initated on a second or more call. Normaly an object in a method will be released after it returns or ends, static will retain that object in place. With the random class you notice that if you do not use the static you can recognize that the random.next gives sometimes a repeated pattern of random numbers, now you can change that by giving it a seed, i usually put in the miliseconds from Now.miliseconds(), combine that with static, that will not be case coz it will not be removed or released andthus will keep giving randoms from the old instance. msdn details: Quote:Normally, a local variable in a procedure ceases to exist as soon as the procedure stops. A static variable continues to exist and retains its most recent value. The next time your code calls the procedure, the variable is not reinitialized, and it still holds the latest value that you assigned to it. A static variable continues to exist for the lifetime of the class or module that it is defined in.
http://www.random.org/ will generate a random number for you efficiently.
(Oct 6, 2014 03:25 PM)Eliza Wrote: http://www.random.org/ will generate a random number for you efficiently. Its not a bad idea, make an API for that and you got yourself a nigty randomizer. But in speed wise, its not gonna be faster then the random class in .net framework ofc True random, its not rly all true random, but we are satisfied by a set of numbers that will change in a way that we can call random ^^ that or keep 10 asians in ur basement and let them memorize some random numbers and yell them if u need it. (Oct 6, 2014 03:31 PM)TheBarret Wrote: Its not a bad idea, make an API for that and you got yourself a nigty randomizer. Why asians? I don't discriminate. Absolutely any person of any race is allowed to be my slave, no judgement. Spoiler (Click to View) (Oct 6, 2014 03:22 PM)IAmNotHere Wrote: Isn't this a bit like dimming a variable under the Public Class Form1 line in the form1.vb also? No that would be a value in that class exposed if its declared, however i rather use specific keywords like Private or Public to either expose the objects and make it easy for myself. static just signals the compiler not to release the current object from a method procedure and an object that is declared with dim would be released upon exit or return. |
|
|
