Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

generate a random number

Well need a easy code but I dont know what to do:
I need to generate a random number like this:
[Image: b0748d24e8ea2d05bdf2deb078ce7e5d.png]

What I can put there? 19 numbers
[Image: ME3mSDm.gif]
Just use Random().Next(1000,9999) and use concat to add them into a row of many
PHP Code

<?php 
Const Chartable As String = "0123456789"
Public Shared Function Randomize(len As Integer) As String
 
Static rnd As New Random(New Object().GetHashCode Mod DateTime.Now.Millisecond)
 Return New 
String(Chartable.Select(Function(x) Chartable(rnd.Next(Chartable.Length))).Take(len).ToArray())
End Function 
ONE instance and one alone now mr barret :)
Code
const string numbers = "0123456789";
Random r = new Random();
string num = "";
for(int i = 0; i<=19;i++)
{
   num += numbers[r.Next(0, numbers.Length -1)];
}
Now you just add num to the URL or whatever you want.

EDIT:

I just realized this is the VB section and not the C#, so my code is useless to you.
(Mar 13, 2017 06:02 PM)BoliBerrys Wrote:  
Code
const string numbers = "0123456789";
Random r = new Random();
string num = "";
for(int i = 0; i<=19;i++)
{
   num += numbers[r.Next(0, numbers.Length -1)];
}
Now you just add num to the URL or whatever you want.

EDIT:

I just realized this is the VB section and not the C#, so my code is useless to you.

you lil fucker replicated my version :P hahahaha 🤣
Heres how i would do it:
Code
Dim r As New Random()
Const charMap As String = "1234567890"

Function GetRandomNumberString(len As Integer) As String
    Dim sb As New StringBuilder(len)
    For i As Integer = 0 To len
        sb.Append(charMap(r.Next(charMap.Length)))
    Next
Return sb.ToString()
End Function

And heres a short verson for the lols
Code
Function GetRandomNumberString(len As Integer) As String
    Return String.Concat(Enumerable.Repeat(Function() charMap(r.Next(charMap.Length)), len))
End Function
Lotta blood to let, peace to make, give a fuk about a check
(Mar 13, 2017 07:29 PM)Barret Wrote:  you lil fucker replicated my version :P hahahaha 🤣

No idea what u coded haha

Sorry if its basically the same 😭😭
(Mar 14, 2017 06:09 PM)BoliBerrys Wrote:  No idea what u coded haha

Sorry if its basically the same 😭😭


Dont sweat it, nothing is ever owned, everything is copied of something. Heck even nature does that. :P
(Mar 14, 2017 07:25 PM)Barret Wrote:  Dont sweat it, nothing is ever owned, everything is copied of something. Heck even nature does that. :P

some one "your" level should know NEVER initialize the random class multiple times.
(Mar 14, 2017 07:35 PM)Sn0wX Wrote:  some one "your" level should know NEVER initialize the random class multiple times.

Its static. There is only one instance.
Lotta blood to let, peace to make, give a fuk about a check
(Mar 14, 2017 09:18 PM)BahNahNah Wrote:  Its static. There is only one instance.

Just ignore it, hes just being silly. Just look beyond and be fine.
Urgh child's time.

Static cant use different seeds.
It's not thread safe.
This is basic GOOD CODING STANDARDS.

but hey when you guys use so many single instances in your apps i would expect you to carry THEM.

oh wait you do not.

You wouldn't be able to use different seeds if it were static - the Random instance keeps track of that state. By default Random uses the current time as seed
(Mar 15, 2017 04:47 PM)Sn0wX Wrote:  Urgh child's time.

Static cant use different seeds.
It's not thread safe.
This is basic GOOD CODING STANDARDS.

but hey when you guys use so many single instances in your apps i would expect you to carry THEM.

oh wait you do not.

You wouldn't be able to use different seeds if it were static - the Random instance keeps track of that state. By default Random uses the current time as seed

What are you talking about? Objects are reference types, the sttaic var just stores the pointer to the random Instance.
Lotta blood to let, peace to make, give a fuk about a check


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by MaskinApr 21, 2021 01:52 AM 5 325 Apr 21, 2021 01:52 AM
Last Post: Vector Dynamics
[C] by Tr0jandogJul 18, 2020 12:05 AM 4 224 Jul 18, 2020 12:05 AM
Last Post: Xora
[C#] by draxyeeDec 28, 2019 03:44 PM 2 294 Dec 28, 2019 03:44 PM
Last Post: Eternal Darkness