473,471 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

random generation of number

38 New Member
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 1555
Banfa
9,065 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
If it is a sequence it is not random. Just start at 0 and add 2 every time.
Jul 25 '10 #4
mar11
38 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Top Contributor
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.