Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random number between -1 and 1
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01387218
Message ID:
01387272
Vues:
55
>>>>I've used the example from help on how to generate random numbers. Now I need a random number between -1 and 1 (integer -1,0,1) and cannot figure out how to modify the example to give negative and positive numbers. Any tips?
>>>
>>>This should work. See the comment because I thought that was odd.
>>>
>>>Random random = new Random();
>>>int i = random.Next(-1, 2); // min is inclusive and max is exclusive for some reason
>>>MessageBox.Show(i.ToString());
>>>
>>
>>Wow! Sorry! That was meant to go to the fox group. BTW - That was between and including -1, 1.
>>
>>Thanks and sorry again!
>
>Check Re: Limited random numbers Thread #1225489 Message #1225509

That is the same as the help file example but it will not provide negative numbers.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform