Hi,
I used Random class for get random numbers, but it bring me a same number every time.
Here is my code:
Random
rnd = new Random();newArr[j++] = (
char)(rnd.Next(65, 122));any ideas?
thanks.
Hi,
I used Random class for get random numbers, but it bring me a same number every time.
Here is my code:
Random
rnd = new Random();newArr[j++] = (
char)(rnd.Next(65, 122));thanks.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sara shatsPosted Jun 18, 2009, 12:40 PM
Niradhip ChakrabortyPosted Mar 19, 2009, 8:56 AM
try this:
protected void Page_Load(object sender, EventArgs e)
{
int intreturnValue = RandomNumber(100000, 999999);
}
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
Vimal KandasamyPosted Mar 19, 2009, 8:38 AM
put Random object creation before the for loop like below.
Random rnd = new Random();
for (int i = 0, j = 0; i < originalArr.Length; i++)
{
newArr[j++] = originalArr[i];
for (int k = 0; k < 2; k++)
{
newArr[j++] = (char)(rnd.Next(65, 122));
}
}
sara shatsPosted Mar 19, 2009, 7:06 AM
I am trying to put 2 random chars between every char in my Array
for (int i = 0, j = 0; i < originalArr.Length; i++)
{
newArr[j++] =
originalArr[i] ;for (int k = 0; k < 2; k++)
{
Random rnd = new Random();
newArr[j++] = (char)(rnd.Next(65, 122));
}
}
The original string was "sara"
the result is "sHHaHHrHHaHH"
I saw in the MSDN help a method: Math.Randomize, (in c# methods), but I can't use it.
What can I do?
thanks a lot!
Vimal KandasamyPosted Mar 19, 2009, 6:55 AM
it may help you to fix the problem
sara shatsPosted Mar 19, 2009, 6:42 AM
I can't find any problem or mistake in my code, it can be an Application error?
or maybe missing any 'using'
(it's asp.net Application whis c# code)
StevePosted Mar 19, 2009, 4:15 AM
Are you just trying to get a random number? or are you trying to throw a random number into an array...?
just random number..
Random myrandom = new Random();
int number = myrandom.Next(min value, max value);
for an array...
Random myrandom = new Random();
int number = myrandom.Next(min value, max value);
int[] myarray = new int[number];
Vimal KandasamyPosted Mar 19, 2009, 4:08 AM
for me it shows different chars.
i execute your code as
Random rnd = new Random();
Console.WriteLine( (char)(rnd.Next(65, 122)));
Console.WriteLine((char)(rnd.Next(65, 122)));
output is
1st time
R
h
2nd
Y
g
3rd
Q
j
problem may be in your code.