473,386 Members | 1,804 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,386 software developers and data experts.

How can I randomly pick either 5 or 8??

How can I randomly pick either the value integer 5 or integer 8??

I don't want a value between 5 and 8 but either the values 5 or 8 randomly.
Any ideas on how can I do this please??

MA
Nov 17 '05 #1
5 1531
Hello

You can try something like this:

double rnd = System.Randow.NextDouble();
int fiveOrEight = (rnd < 0.5) ? 5 : 8;

Aleksandar

"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
How can I randomly pick either the value integer 5 or integer 8??

I don't want a value between 5 and 8 but either the values 5 or 8
randomly.
Any ideas on how can I do this please??

MA

Nov 17 '05 #2
try this:

Create a System.Random type that generates a value between 1 and 12. ( I
chose 1 - 12 so that the value '8' has the same distance to the "upper bound"
as '5' does to the "lower bound")

Subtract the random value from 5, then from 8. Which ever operation
produces the smallest absolute value, then use the value (5 or 8)that
produced this result. For instance, if the random value is 6, then then the
results will be -1, and 2. (5 - 6) results in the smallest absolute value,
therefore 5 would be selected based on this logic.

"Paul Tomlinson" wrote:
How can I randomly pick either the value integer 5 or integer 8??

I don't want a value between 5 and 8 but either the values 5 or 8 randomly.
Any ideas on how can I do this please??

MA

Nov 17 '05 #3
Thanks both. I forgot to mention that 5 and 8 are variable. I'll work with
the 0.5 double I think :->
Nov 17 '05 #4
I like this suggestion better than mine. Its much less complicated, more
elegant.

"Aleksandar" wrote:
Hello

You can try something like this:

double rnd = System.Randow.NextDouble();
int fiveOrEight = (rnd < 0.5) ? 5 : 8;

Aleksandar

"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
How can I randomly pick either the value integer 5 or integer 8??

I don't want a value between 5 and 8 but either the values 5 or 8
randomly.
Any ideas on how can I do this please??

MA


Nov 17 '05 #5

"Paul Tomlinson" <ru************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
How can I randomly pick either the value integer 5 or integer 8??

I don't want a value between 5 and 8 but either the values 5 or 8
randomly.
Any ideas on how can I do this please??

MA


Pick a number from 0 to 1 (integer), if 0 then choose 5, otherwise choose 8
:)

Mythran

Nov 17 '05 #6

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

Similar topics

5
by: Joe Six-Pack | last post by:
Hi, Im having problems in randomly selecting an element in an array that has not been selected before.. in other words, I have an array of answers to questions, then I want to select 5, with one...
1
by: allyn44 | last post by:
Hi--I ned to randomize a calculation result to put it into 1 of 2 groups. Can I use the randomize funciton for this? Basically i ahve this: If sum> 0 set group =1 If sum < 0 set group =2 ...
4
by: Davy | last post by:
Hi all, I have a Set contain several elements. I want to do: (1) Select one element from Set randomly; (2) Delete this element from Set; (3) If Set!=empty, goto(1);else, end. Is there any...
2
by: Chris Green | last post by:
I would welcome any advice someone could offer on the follow problem. I need to code a command line utility in c sharp. The utility will accept a single parameter; the name of a cs file (not an...
0
by: Seth Broomer | last post by:
i have a site that stores about 5-6 cookies randomly the cookies will either expire, or just lose its value what i'm doing is pretty simple. when the user logs in i save some of their data...
3
by: brian | last post by:
Hello, Can someone tell me how I can randomly assign a file to a variable from a directory. Example: Dim File as string I need to search through 'C:/Comics/' and have the program randomly...
9
by: Alan Isaac | last post by:
I need access to 2*n random choices for two types subject to a constraint that in the end I have drawn n of each. I first tried:: def random_types(n,typelist=): types = typelist*n...
5
by: John | last post by:
How can I fill an array randomly so it contains a certian range of numbers (1 - 100 for example) ? My Goal is to generate a set of numbers in random order.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.