Hi all,
I have to randomlly pick numbers, but not any any number, it has to be from
a predefined set of posible values. Is there an "easy" way to do that????
TIA,
Sebastián 12 1757
Hi,
What you can do is get the probables values in an array, then select a
randon from 0 .. array.length - 1
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message
news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do that????
TIA, Sebastián
Here's a solution:
Create an array with the size of the number of dedired values. Populate the
array with the desired values, then find a random position in the array
(using the length of the array as part of the randomization).
How about that?
--
venlig hilsen / with regards
anders borum
--
On Mon, 13 Dec 2004 08:37:57 -0500, Ignacio Machin ( .NET/ C# MVP )
<ignacio.machin AT dot.state.fl.us> wrote: Hi,
What you can do is get the probables values in an array, then select a randon from 0 .. array.length - 1
Cheers,
If the values can be picked only once (ie a card deck) use an ArrayList
and remove the picked 'card'.
--
Happy Coding!
Morten Wennevik [C# MVP]
Hello
Something like this should work..
Random random = new Random();
int [] predef = {15,22,33,6,.....};//eg, 25 predefined mumbers
int index = random.Next(0,25);//get a random index
int num = predef[index];
"Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message
news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do that????
TIA, Sebastián
In addition, if the set is contiguous, then you can just use the
overload of Next on the random class and it will return a number in that
range for you.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:OK**************@TK2MSFTNGP14.phx.gbl... Hi,
What you can do is get the probables values in an array, then select a randon from 0 .. array.length - 1
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do that????
TIA, Sebastián
Gracias Ignacio...
So, I should create an array with the values I want the numbers from???
How do I get those values randomly?
Saludos.-
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:OK**************@TK2MSFTNGP14.phx.gbl... Hi,
What you can do is get the probables values in an array, then select a randon from 0 .. array.length - 1
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do
that???? TIA, Sebastián
Here's some code I just put together ..
int[ ] list = new int[5];
list[0] = 1;
list[1] = 23;
list[2] = 34;
list[3] = 45;
list[4] = 56;
int foundNumber = list[new Random().Next(list.Length)];
--
venlig hilsen / with regards
anders borum
--
It is not contiguous...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl... In addition, if the set is contiguous, then you can just use the overload of Next on the random class and it will return a number in that range for you.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:OK**************@TK2MSFTNGP14.phx.gbl... Hi,
What you can do is get the probables values in an array, then select a randon from 0 .. array.length - 1
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do
that???? TIA, Sebastián
Thank you all!!!
It's been great help!
"WRH" <no**********@videotron.ca> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl... Hello
Something like this should work..
Random random = new Random();
int [] predef = {15,22,33,6,.....};//eg, 25 predefined mumbers
int index = random.Next(0,25);//get a random index
int num = predef[index];
"Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message news:%2********************@TK2MSFTNGP12.phx.gbl.. . Hi all, I have to randomlly pick numbers, but not any any number, it has to be from a predefined set of posible values. Is there an "easy" way to do
that???? TIA, Sebastián
"Sebastián" <NO***********@poderjudicial.gub.uy> wrote in message
news:##**************@TK2MSFTNGP12.phx.gbl... Hi all, I have to randomlly pick numbers, but not any any number, it has to be
from a predefined set of posible values. Is there an "easy" way to do that????
TIA, Sebastián
If your number selection is from a predetermined set, the selected numbers
are no loger random.
If you want to select them within a range, that is different and doable.
Zach <00@00.00> wrote: If your number selection is from a predetermined set, the selected numbers are no loger random. If you want to select them within a range, that is different and doable.
In what way is the predefined set {0, 1, 2, 3, 4} different from
selecting integers in the range [0,4], for example?
Any range of integers is a set. Picking random numbers from a set is
still picking numbers at random.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
The set was {1,5,10,20,50,100}
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Zach <00@00.00> wrote: If your number selection is from a predetermined set, the selected
numbers are no loger random. If you want to select them within a range, that is different and doable.
In what way is the predefined set {0, 1, 2, 3, 4} different from selecting integers in the range [0,4], for example?
Any range of integers is a set. Picking random numbers from a set is still picking numbers at random.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Frank Millman |
last post by:
Hi all
I was helping my niece with her trigonometry homework last night. Her
calculator's batteries were flat, so I thought I would use Python's
math module to calculate sin, cos, and tan.
I...
|
by: limelight |
last post by:
I have discovered a math error in the .NET framework's Log function. It
returns incorrect results for varying powers of 2 that depend on whether the
program is run from within the IDE or from the...
|
by: Reiner Apke |
last post by:
Hello,
I have got a very strange problem with the calcualtion of the the square
root (Math.Sqrt()).
I calculate in a loop a lot of of diameters
maxDiameter = Math.Sqrt(maxCrossSection *...
|
by: Ark |
last post by:
Hi everyone,
Does anyone know if Direct3D overloads System.Math
functions?
Also is it possible to access the base functions of the
overloaded function (in other words restore original of
the...
|
by: ng_mr |
last post by:
No, not a question about "banker's rounding" or whatever it's called.
I want to round a double to the nearest 100th, so I perform the
following:
// original is a double
double result =...
|
by: Gregory Pietsch |
last post by:
I'm writing a portable implementation of the C standard library for
http://www.clc-wiki.net and I was wondering if someone could check the
functions in math.h for sanity/portability/whatever. I'm...
|
by: Sambo |
last post by:
I have the following module:
-------------------------------
import math
def ac_add_a_ph( amp1, ph1, amp2, ph2 ):
amp3 = 0.0
ph3 = 0.0
ac1 = ( 0, 0j )
ac2 = ( 0, 0j )
|
by: David Coleman |
last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1)
In the Command Window I get the following
? Math.Round(0.715, 2)
0.72
? Math.Round(0.725, 2)
0.72
? Math.Round(0.735, 2)...
|
by: =?Utf-8?B?UmVuZQ==?= |
last post by:
Hello everyone
I have a problem with Math.Round, it´s ocurring some strange:
Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99
Why?? What is the problem?
Help ME !!!!
|
by: Lenni |
last post by:
Hi,
I'm currently writing a web application for bicycle wheel builders
that calculate the spoke length for all sorts of variations of hubs
and rims.
I have translated the formula from an...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |