|
-
Feb 12th, 2000, 11:57 PM
#1
Thread Starter
Addicted Member
I have a problem
I want my app to ask for an integer and then use it to create a series random-numbers based on the integer.
I have tried Randomize x (where x is the integer) under Fomr_Load, but it doesn't work to change it durin runtime. And since I can't base my program on letting the user change the source-code everytime he wants a different series, what can I do?
Hope anyone can help.
Pentax
------------------
Wilhelm Tunemyr,
Sweden
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda zvítezi!
-
Feb 13th, 2000, 01:16 AM
#2
Hyperactive Member
Use Randomize. It is based on system Timer, therefore each time you get a different series, as you want:
----------
Randomize
MyNumber = Rnd * etc. etc.
----------
or:
----------
Randomize Timer
etc. etc.
----------
-
Feb 13th, 2000, 04:37 AM
#3
Thread Starter
Addicted Member
Well, thanks for your help, but I'm afraid it doesn't really help with my problem.
I use it for encryption.
If I use Rnd(x) with x<0 I'll get the same number every time. This makes the encrypted text easy to break.
If I use Rnd(x) with x>0 I'll the same series regardless of what x I use. This works, but the user can't choose a unique seed, which means all texts will be encrypted the same way. And thus easy to break.
If I use Randomize(x) in the Form_Load I'll get an unique series of numbers, depending on what x I use, but I can't let the user choose x
So I need to let the user choose a seed, and get a random series based on it so he will get the same series every time he uses the same seed, but a different if he changes seed.
If anyone has an idea, pleas help me!
Thanks,
Pentax
------------------
Wilhelm Tunemyr,
Sweden
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
Heinrich Heine (1797-1856)
Pravda zvítezi!
-
Feb 13th, 2000, 07:24 AM
#4
Hyperactive Member
Oh, I misunderstood you!
So you want your user to input kind of a password and based on it obtain different random series? That's easy!
------
Randomize Text1.Text
For I = 1 to Whatever
MyNumber = Rnd * etc etc
Next
------
1- Be sure Text1.Text only allows numbers
2- As long as you enter the same value to Randomize, your series will repeat itself.
-
Feb 13th, 2000, 12:40 PM
#5
this is from the MSDN cd...
Returns a Single containing a random number.
Syntax
Rnd[(number)]
The optional numberargument is aSingle or any validnumeric expression.
Return Values
If number is Rnd generates
Less than zero, The same number every time, using number as the seed.
Greater than zero, The next random number in the sequence.
Equal to zero, The most recently generated number.
Not supplied, The next random number in the sequence.
Remarks
The Rnd function returns a value less than 1 but greater than or equal to zero.
The value of number determines how Rnd generates a random number:
For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.
To produce random integers in a given range, use this formula:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.
Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.
i guess you're going to have to use a negative number as the seed
[email protected]
[This message has been edited by wossname (edited 02-13-2000).]
-
Feb 13th, 2000, 12:43 PM
#6
Hyperactive Member
X = Text1.Text 'the user's number
For I = 1 to 100
Y = Int(RND * X)
Text2.Text = Y 'where the results go
Next I
This will put a bunch of numbers into Text2.Text too fast for you to see, but it will happen nonetheless. All the numbers will be between 0 and X. If you wanted the number of numbers to be random, try this:
X = Text1.Text
For I = 1 to X
Y = Int(RND * 100)
Text2.Text = Y
Next I
Hope it works for you.
bob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|