How to use Rand()

Ask general questions here.
mpolyakov
Posts: 1
Joined: Mon Nov 02, 2009 3:14 am

How to use Rand()

Post by mpolyakov » Mon Nov 02, 2009 3:46 am

How to use Random function (C#) when you need to select random item from two dimensional array?
MP

User avatar
Support Team
Site Admin
Site Admin
Posts: 11720
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to use Rand()

Post by Support Team » Mon Nov 02, 2009 9:38 am

That`s quite easy. Generate a random number between your array range in the 2 dimensions

.e.g.
// for Array[100][80]
Random random = new Random();
int xPos = random.Next(100);
int yPos = random.Next(80);
and take the array content from your random position.

Best regards,
christian
Ranorex Supoort Team
.
Image