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

random generation of number

38
Hi all,

I want to generate a number between 0 and 1023 and the difference between two generated number is always 2, e.g. 1, 3, 5, ...., 1023.

through modulo I can generate a number between 0 and 1023 but I can not find a formula to generate the desired number sequence..

any suggestion...

Best wishes,
Mar
Jul 25 '10 #1
6 1553
Banfa
9,065 Expert Mod 8TB
Are you saying you want to generate a number X between 0 and 1023 and then a second number that is either X+2 or X-2 or are you saying you want to generate an odd number in the range 1<= X <= 1023?
Jul 25 '10 #2
mar11
38
I want to generate a number in the range between 0 and 1024. The sequence should be as the following: 0, 2, 4, 6,.. 1024. Each time I call the formula it should be generated one number like it is described above.
Jul 25 '10 #3
Banfa
9,065 Expert Mod 8TB
If it is a sequence it is not random. Just start at 0 and add 2 every time.
Jul 25 '10 #4
mar11
38
I meant by each call I want to get through random as following:

1 call: generated 2
2 call: generated 8
3 call: generated 600
4 call: generated 212

and so on.. and the range is between 0 and 1024..

I hope the idea is clear now..
Jul 25 '10 #5
Banfa
9,065 Expert Mod 8TB
So you want a number X such that 0 <= X <= 1024 and X is even.

First question then is how many values are actually in that range? The answer 1024/2 + 1 = 513. So you need to generate 513 unique numbers or a number Y such that 0 <= Y < 513 or a number in the range 0 - 512.

That should be easy using the modulus operator you mention in your first post. Then all you need to do is map those numbers onto the numbers you actually want, that is also easy

X = Y * 2
Jul 25 '10 #6
donbock
2,426 Expert 2GB
Generating a random integer between 0 and 1023 is straightforward. Is that what you want?

I don't understand what you mean by "the difference between two generated numbers is always 2". The example you gave in reply #5 does not seem to obey that constraint.

Is it important to you for your program to follow the same random sequence every time you run it; or is it important that the results be different each time you run the program? The answer to this question determines whether you need to seed the random number generator with a fixed constant or with a different value each time the program executes.
Jul 25 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: abhinay07 | last post by:
Hi, I would like to generate random values which are in bimodal distribution. If I can give the two peak means and the variance values, can I get any function to generate them from the uniform...
3
by: WJ | last post by:
When register oneself to do business online, at thew end of registration page, there is a Graphic that contains a string of number, you are required to enter this string before prewssing the...
1
by: mike g | last post by:
Hello, I have postgres set to log all connections. I run it on port 5432. I have noticed in the postgres logs that the port being used to connect to the database is logged but never equal to...
1
by: FX | last post by:
Hi all, How can I get a random long number ? (nb: Random class allows me to generate only int number, I would like number possibly greater than int.MaxValue)
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
3
by: y Muralidhar Rao | last post by:
Hi, this is murali, Please any one help me to get the code for random genreation of numbers, like to get the recordsin datagrid comes randomly each time i view the output.
2
by: carrot | last post by:
The question is : Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. Do not let the first three digits contain an 8 or 9...
4
by: hebaahmed | last post by:
How do I determine random prime numbers in RSA? I have already generated numbers but can't check if prime or not. Here is the part of generation public static void main(String args) throws...
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: 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:
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.