I know this may sound like a weird question to ask but I would like to know how to have the code randomly pick a memory loc开发者_如何学Pythonation in an Array without having it filled, perferably in VB.NET
Thinking of the logic, I was thinking
Dim random As Random
Dim tic(2, 2) As String
random.Next(tic(2,2))
Would putting the array as a parameter would randomly pick a memory location in an array? Yeah I really don't know what I'm talking about so I really need to be led on the right path if possible.
Are you just looking for a random index for the array to fill it with data?
Dim x = random.Next(2)
Dim y = random.Next(2)
tic(x,y) = "Some value"
Something like this:
Dim random as New Random
Dim tic(2, 2) As String
' Use UBound instead of 2, if your array may be a different size.
Dim i As Integer = random.Next (0, 2)
Dim j As Integer = random.Next (0, 2)
Console.WriteLine (tic(i,j))
Here's how you could do it in CSharp...
Random random = new Random();
int len1 = 2;
int len2 = 2;
string[,] tic = new string[len1, len2];
string nextString = tic[random.Next() % len1, random.Next() % len2];
精彩评论