473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Random Value

Hello,

I declared, in my aspx.vb code, a variable of type integer.

How can I set its value to a random value which can be only 1,2,3 or 4?

Thanks,
Miguel

Nov 19 '05 #1
3 1508
Simply use the System.Random() method.

Here's an example:
http://www.devx.com/vb/Article/16410/0/page/3

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hello,

I declared, in my aspx.vb code, a variable of type integer.

How can I set its value to a random value which can be only 1,2,3 or 4?

Thanks,
Miguel

Nov 19 '05 #2
Dim X As new Random()
Dim theNum As Short = x.Next(1,5)

Notice the max. value is set to 5, not 4. This is not very well documented,
but you will never get the max. value you specify, only values up to, but
not including the max.

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hello,

I declared, in my aspx.vb code, a variable of type integer.

How can I set its value to a random value which can be only 1,2,3 or 4?

Thanks,
Miguel

Nov 19 '05 #3
Thank You Both.

Cheers,
Miguel

"Scott M." <s-***@nospam.nospam> wrote in message
news:s-***@nospam.nospam:
Dim X As new Random()
Dim theNum As Short = x.Next(1,5)

Notice the max. value is set to 5, not 4. This is not very well documented,
but you will never get the max. value you specify, only values up to, but
not including the max.

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hello,

I declared, in my aspx.vb code, a variable of type integer.

How can I set its value to a random value which can be only 1,2,3 or 4?

Thanks,
Miguel


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
9
by: abhi | last post by:
How do you get random numbers in vb .net? I want random six digit numbers. Cheers, Abhi
13
by: porterboy76 | last post by:
If you only use a 32 bit seed for a random number generator, does that mean you can only ever produce a maximum of 2^32 (approx 4 billion) different sequences? What about the Mersenne Twister,...
1
by: ssims | last post by:
I've got this code for a random GDI+ chart generator, and the demo works, but when I try to run it on my local machine I get a compiler error: Compiler Error Message: CS0117: 'Random' does not...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
7
by: teh.sn1tch | last post by:
I created a random number generator for an application that uses a MersenneTwister class I found on the net. Basically I generate two random numbers from the MersenneTwister class and use each one...
20
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random...
3
by: Army1987 | last post by:
Is there anything wrong with this program? It seems to behave strangely if I give stdin EOF when asked for the character set... /* BEGIN pwdgen.c */ #include <stdio.h> #include "random.h"...
1
by: Alan Mailer | last post by:
I want to periodically generate a completely new random Long value in some code I'm writing. The value need not be based on anything in particular, I just need to know that if I have to generate...
11
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.