|
The OP simply requested unrepeated, not random. Truly random numbers must be allowed to repeat (otherwise you are choosing from a smaller and smaller pool). For serial numbers Nathan's approach sounds fine, how you combine (or mangle) the two/three components depends on the user's requirements.
Another approach is to take the numbers 1,2 .. 100,000 and encrypt or hash them, but this is not as simple as Nathan's approach. If you encrypt them it is possible to find the original serial number if this is important.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Agreed. The original post asked for "unrepeated" and "nonconsecutive". By itself, this is really easy (10^6, 10^6 +2, 10^6 + 4, ...), and so I simply assumed he misasked his question.
Specifically I assumed that he wanted a random sample from that range without replacement. Like I told him, without getting a better requirements list, it wasn't going to be possible to answer his question properly.
Assuming he means "a random sample without replacement", I think my method (just generate the numbers) is best. The only problem here is that there aren't any guarantees they are unequal.
If you could "fudge" the randomness a bit, a previous poster came up with a good method (although in his method, you should put the random portion of the numbers first, then the sequential part, to maximize randomness). That method would generate 100K numbers that will be close to uniformly distributed.
You could also generate the numbers randomly and just keep the already generated ones sorted, so you can just check to see if they are in the list. This would produce the most accurate result, although also would take the most work (you'd have to do an extra insert and search into some data structure for each of your 100K iteration).
Finally, if you are comfortable with the theoretical foundations of random number generators, you might have some interesting possibilities there. As you might know, many of the most common RNGs are "Linear congruential RNGS". Each RNG of this type is defined by 3 numbers, a, b, and m. You start with an initial seed, n_0, and the number that comes out is (a*n_0 + b) mod m. That is your random number. By reapplying the formula with the JUST generated number will get you your second random number and so on. As far as this class of generators goes, there is an art and a science to picking "good" numbers" I think if you worked at it for an hour, you could figure out how to pick a, b, and m such that you could get a "uniform random without replacement" sample of 100K. I would guess this could be "the best" way, but it would require a little mathematical knowledge (nothing you can't get in a couple hours on wikipedia), and if you didn't know what you were doing, it would be pretty easy to mess it up. (I haven't looked at this in a while, but I think if you pick a prime as close to (10^17 - 10^16) as possible, and then get REALLY REALLY big a and b, you'd be ok.)
On the other hand, if unique and non-consecutive is REALLY what he wants, the following will do the trick:
std::vector<double> myVector;
myVector.reserve(100000);
int inserted = 0;
double baseNum = pow(10, 16);
while (inserted != 100000)
{
myVector.push_back(baseNum);
baseNum += 2;
}
will do exactly that.
|
|
|
|
|
Guess we had different takes on the original question, but it does raise some interesting ideas, as long as we agree that they may have nothing to do with the original post.
I was looking at the serial number aspect, which I interpreted to be the type of alpha-numeric key type things you have to type in to install some software. Here the requirements MAY be:
1. hard to create valid serial numbers without the exact algorithm
2. easy to check if a serial number is valid
For 100,000 serial numbers, with 16 digits, if all numeric then only 10^5 of 10^16 are valid, so if the numbers appear 'random', the chance of creating one by guessing is 1 in 10^11. If the digits can be alphanumeric then the chance is lower.
Tim's approach of mangling bits from a sequence number, a random number and some hash value is a simple solution to this, likely to be adequate for many applications. However, if these numbers are to be tested for validity in the field, it is vulnerable as it places the algorithm needed to generate the serial numbers actually in the field software, so is susceptible to reverse engineering. As to whether this is a problem depends on waht you are trying to achieve.
You can make it safer using public key cryptography. For example, if you were to encrypt the blocks{serial_000001, serial_000002, serial_000003.. etc} using an RSA private key, then you could decrypt using the RSA public key in your software. Only valid serial numbers would decrypt to something of the correct form. It would be very difficult to generate valid numbers without the private key. This can only be part of a security system, but is a relatively simple way to make keys that are hard to fake.
You could generate random numbers using linear congruences, 'good' here usually refers to mathematical randomness; the uniform (or specifically shaped) distribution and lack of hidden correlation, characteristics essential for their use in monte-Carlo simulations. There is lots on the web on this, Numerical Recipes have a simple canned routine. For serial numbers though, Random numbers don't have a simple way of determining if a particular number is valid.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
First I wanna tell u that I am not well in English.
I wanna get some help from you.
Now I am making a mathematics project with VB.NET.
My idea is type a mathematics equation into a textbox.
Example: e^x + ln x , 3x^2 + 5x - 2 , sin x - cos^2 x , etc.
I don't wanna write the whole equation in coding time.
I'll write each part of mathematics functions i.e, sin(), cos(), exp(),ln(), etc.. in coding time.
I wanna get that when I type a equation into textbox and then click to commandbutton, corresponding function will automatically work and generate the correct answer.
I will very thanks you if you can help my problem.
phowarso
|
|
|
|
|
Yeees I'm reading reading and reading and I just can't find any question in your post hmmmmmmm
phowarso wrote: First I wanna tell u that I am not well in English.
I wanna get some help from you
I can not help you with your English :] Maybe try to take some extra courses/lessons.
As regards to the rest of your post:
phowarso wrote: Now I am making a mathematics project with VB.NET.
My idea is type a mathematics equation into a textbox.
Example: e^x + ln x , 3x^2 + 5x - 2 , sin x - cos^2 x , etc.
I don't wanna write the whole equation in coding time.
I'll write each part of mathematics functions i.e, sin(), cos(), exp(),ln(), etc.. in coding time.
I wanna get that when I type a equation into textbox and then click to commandbutton, corresponding function will automatically work and generate the correct answer.
That's cute... All what I can do is wishing you luck in your work. If you have some concrete problem with some part of code we will try to help you.
|
|
|
|
|
Hello
Friend
Thanks you for your encouragement.
I'll hopping for your help...
with best wishes,
phowarso
|
|
|
|
|
Hello
Friend
Thanks you for your encouragement.
I'll hopping for your help...
with best wishes,
phowarso
|
|
|
|
|
I don't have any significant VB experience, but there are lots of examples of this sort of thing in C++. If you are stuck, look at Stroustrup's book "The C++ Programming Language" where he shows how to do basically what you want to do in C++. Parsing the expression is the key, and the simple solutions often use a technique called recursive descent, so you could try to find articles with keywords "recursive descent" and "visual basic".
Update: I just googled on these terms and the first hit was:
http://www.codeproject.com/vb/net/math_expression_evaluator.asp[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hello!!!
At the beginning I want to say: My english isn't very well.
In C# I wrote 8 queens genetic Algorithm and now I want to write genetic algorithm solving problem "Chess Hopper". Can you help my do it?
Thanks a lot from something...
|
|
|
|
|
Can you describe the Chess Hopper?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hello everyone,
I tried through google but found nothing but theoric info. If anyone knows what the "Rough Set Algorithm" is exactly, what it is used for and have a sample code please help me.
Do I want too much ?
Thanks and best regards.
.:: Something is Wrong ::.
|
|
|
|
|
pashje wrote: tried through google but found nothing but theoric info
Same here. You might have to dig through the theory stuff and implement your own code.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hi all,
What is the best way to check whether a cube intersects with a rectangle,
Remember both the and rectangle can be in any position (rotated ).
Cheers
KD
If u can Dream... U can do it
|
|
|
|
|
if you treat the rectangle as a cube with a length of zero on one dimension I'm sure you can find multiple implementations online.
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
An international team of 18 mathematicians, including two from MIT, has mapped one of the largest and most complicated structures in mathematics. If written out on paper, the calculation describing this structure, known as E8, would cover an area the size of Manhattan.
Article[^].
Lecture slides[^].
Come and see the violence inherent in the system! Help! Help! I'm being repressed!
|
|
|
|
|
those mathematics are SO out of my leage.
what is 1+1 again ?
|
|
|
|
|
11
--
CleaKO The sad part about this instance is that none of the users ever said anything [about the problem].
Pete O`Hanlon Doesn't that just tell you everything you need to know about users?
|
|
|
|
|
"Mathematicians study symmetries in higher dimensions. E8 has 248 dimensions."
Maximilien wrote: those mathematics are SO out of my leage.
Nah, they probably just run 248 nested for
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Maximilien wrote: what is 1+1 again ?
10
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
I was about to post the same answer.
|
|
|
|
|
Hi to all, i'm a Biogenetic student and i don't know anything about programming.
Now, i'm looking for someone that can help me to implement some simple phylogenetic algorithms that construct phylogenetic relationship among biological sequences.
There are some kinds of algorithms, such as the follow: Clustering Algorithms, Cladistic methods. I haven't limitation in programming about one algorithm in particular.
What i found is a simple program that draw, in a Windows Form, the output of one o this methods.
Please help me.
|
|
|
|
|
bufugus wrote: Now, i'm looking for someone that can help me to implement some simple phylogenetic algorithms that construct phylogenetic relationship among biological sequences.
There are some kinds of algorithms, such as the follow: Clustering Algorithms, Cladistic methods. I haven't limitation in programming about one algorithm in particular.
Are you asking for a library or are you saying you have them and are asking how to use them?
bufugus wrote: Hi to all, i'm a Biogenetic student and i don't know anything about programming.
You'll need to do something about that if you expect to make a program that works. Unfortunately you can't just copy and paste different code libraries and expect them to work together without writing some code to tie it all together.
What you are trying to do would be like trying to make a new type of car without knowing how cars work. Even if you found companies to make all the parts for you you still would need to know how to assemble them. The same thing goes for programming you need to learn how to program even if only to assemble various code libraries(if you could find libraries for everything, doubtfull).
I would recommend you buy a book or get one from a library to teach you how to program. vb.net is probably one of the easiest languages to learn, but you might also look at c# which is a little more difficult but probably has more libraries written for it. Stay away from c++ though.
|
|
|
|
|
I think he is asking for a programmer who would implement those algorithms for him (and while he doesnt say that, I think visualization as well), to support his biological study/presentation/whatever. Why should he need to learn programming? That's what programmers are for
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
yeah now that I reread it you may be right. Good point.
|
|
|
|
|
I agree with the point of what you're saying, but not the specific advice.
My advice to any university student/post doc/academic who is looking to learn bioinformatics, I would say "DO NOT learn vb.net. Don't learn C# either." (although c# wouldn't be as bad as vb.net).
Now, I haven't ever used either of those languages, so I don't actually know whether or not they would be better or not than my own recommendations. All I can say is that in the academic bioinformatics world (I don't know what is standard for industry) the languages to learn would be Perl, Python, and C++. Perl is more popular, although I would recommend Python is the better choice (better syntax, better language features, easier to work with, a more promising future) between the two. Any serious bioinformatics student MUST learn one or the other. C++ isn't essential, but you move ahead if you know it well.
For better or worse (I'm not judging today), using C# will set you off in the corner and get you funny looks from the community/your colleagues. Using vb.net will probably get you completely shunned (my boss, who is a mathematician/scientific programmer, spends his free time working on a multi-threaded, garbage collected implementation of lisp -- imagine how he would respond to someone saying their language of choice was vb.net).
In my few years of experience, the academic scientific programming world does not in any way resemble the industrial programming world. I know of a single example of a scientific programming project using c# (which is regarded as a huge mistake by everyone else). Everything else is almost exclusively written in C, C++, Perl, or Python. A couple java programs here and there, too. One law of human behavior is that to be accepted by a group, you'll have to conform to the culture of that group, and that rule applies here. So learn Python or Perl first (but you should choose Python).
I don't have time to do it for anyone, but there are numerous online python tutorials that are specifically written for bioinformatics. I also would highly recommend Biopython[^] as a great library that will help you represent various biological sequence types (amino acid, dna, rna, etc). Finally, and probably most importantly, I would recommend the book Biological Sequence Analysis by Durbin, Eddy, some other guys. It's a fantastic book, and gives a great overview to the field (I dont recall if it discusses clustering specifically, but it talks about everything else). It's a little heavy on the math, but if you're doing statistical analysis of patterns in huge data sets, you'd better accept "a little heavy on the math" as a fact of life.
|
|
|
|
|