program that senkeys a random digit - vbscript

I have to make a vbscript program that sendkey's a random 6 digit nomber, any ideas?
I tried this
WscriptSchell.SendKeys "randomNumber = Int( (999999 - 100000 + 1) * Rnd + 100000

Create a file (for example test.vbs) with that content and run it:
Randomize
WScript.CreateObject("WScript.Shell").SendKeys Int((999999 - 100000 + 1) * Rnd + 100000)
Info:
Randomize must be called before Rnd to get random results.

Related

For from a range(0, value goal)

'Hi, I'm trying to calculate how many months to achieve a million dollars with compounding interest and monthly investments. There are my tries.'
'This first code work, but I want to replace the 92 in the rage with a compare formula like fv >= 1000000.'
'When I place the range like here, it doesn't work.'
Try while-loop may help:
pv = 130000 # present value
i = 4000 # regular monthly investment
r = 0.1375 # annual interest rate
n = 0 # number of months
# for n in range(0, 92):
fv = 0
while fv < 1000000:
fv = pv * (1 + r / 12) ** n + i * (((1 + r / 12) ** n - 1) / (r / 12))
n += 1 #don't forget
print(fv)
print(n)
You need to manually increase the value of n

work out how many seconds have expired in total during game play

~Why the hell has this had down votes.... you people are weird!
Ok so this is a very simply HTML5 and jQuery and PHP game. Sorry to the people who have answered, I forgot to say this is a php script, i have updated here to reflect.
the first level takes 1 minute. Every level after that takes an extra 10 seconds than the last level. like so;
level 1 = 60 seconds
level 2 = 70 seconds
level 3 = 80 seconds
level 4 = 90 seconds
and so on infinitely.
I need an equation that can figure out what is the total amount of seconds played based on the users level.
level = n
i started with (n * 10) + (n * 60) but soon realized that that doesn't account for the last level already being 10 seconds longer than the last. I have temporarily fixed it using a function calling a foreach loop stopping at the level number and returning the value. but i really want an actual equation.
SO i know you wont let me down :-)
Thanks in advance.
this is what i am using;
function getnumberofsecondsfromlevel($level){
$lastlevelseconds = 60;
while($counter < $level){
$totalseconds = $lastlevelseconds+$totalseconds;
$lastlevelseconds = $lastlevelseconds + 10;
$counter++;
}
return $totalseconds;
}
$level = $_SESSION['**hidden**']['thelevel'];
$totaldureationinseconds = getnumberofsecondsfromlevel($level);
but i want to replace with an actual equation
like so;(of course this is wrong, this is just the example of the format i want it in i.e an equation)
$n = $_SESSION['**hidden**']['thelevel']; (level to get total value of
in seconds)
$s = 60; (start level)
$totaldureationinseconds = ($n * 10) + ($s * $n);
SOLVED by Gopalkrishna Narayan Prabhu :-)
$totalseconds = 60 * $level + 5* (($level-1) * $level);
var total_secs = 0;
for(var i = 1; i<= n ;i++){
total_secs = total_secs + (i*10) + 50;
}
for n= 1, total_secs = 0 + 10 + 50 = 60
for n= 2, total_secs = 60 + 20 + 50 = 130
and so on...
For a single equation:
var n = level_number;
total_secs = 60 * n + 5* ((n-1) * n);
Hope this helps.
It seems as though you're justing looking for the equation
60 + ((levelN - 1) * 10)
Where levelN is the current level, starting at 1. If you make the first level 0, you can get rid of the - 1 part and make it just
60 + (levelN * 10)
Thought process:
What's the base/first number? What's the lowest it can ever be? 60. That means your equation will start with
60 + ...
Every time you increase the level, you add 10, so at some point you'll need something like levelN * 10. Then, it's just some fiddling. In those case, since you don't add any on the first left, and the first level is level 1, you just need to subtract 1 from the level number to fix that.
You can solve this with a really simple mathematical phrase (with factorial).
((n-1)! * 10) + (60 * n)
n is the level ofcourse.

Generating a random number?

Hi i need a program that allows me to generate a random number but it needs to be a number with the same consecutive numbers like 222,5555,666,44,11.The program will keep generating until a number with the same consecutive numbers come up and stop. this is what i have so far. thanks for the help.
int entierA8 = rnd.nextInt(10000 - 1) + 1;
System.out.println("\n8.");
do{
entierA8 = rnd.nextInt(10000 - 1) + 1;
System.out.println("Random number genrated: " + entierA8);
}while();

Random number from 0 to 100 in QBasic

I need a totally random number from 0 to 10 or from 0 to 100 as a value "NUM" done in QBasic for a random draw program. I currently have this:
RANDOMIZE TIMER: A = INT((RND * 100)): B = INT((RND * 10)): C = (A + B)
NUM = INT(C - (RND * 10))
This is basically just a pile of random mathematical operations to get a random number from 1 to 100.
The problem is i get the same or very similar numbers quite too often. Is there a more reliable way to do this?
The code that you provide does not at all meet the requirement of a "random number from 0 to 10 or from 0 to 100". You start out setting A to a random number from 0 to 99 and B to a random number from 0 to 9. But the rest of your calculation does not perform an "OR".
How about this:
RANDOMIZE TIMER
A = INT(RND * 101) // random number from 0 to 100
B = INT(RND * 11) // random number from 0 to 10
C = INT(RND * 2) // random number from 0 to 1
IF C = 0 THEN
NUM = A
ELSE
NUM = B
END IF
or more simplified:
RANDOMIZE TIMER
NUM = INT(RND * 101)
IF INT(RND * 2) = 0 THEN
NUM = INT(RND * 11)
END IF
Try this Rand function used as
NUM = Rand(0, 100)
For getting a random number from 0 to any number , you can use the following program -
Randomize timer
Rand_num = INT(RND(1)*limit)+1
Where-
Rand_num= the random number
Limit = the last number like if you want from 0 to 100 then limit will be 100

How do I generate a number in a percentage range?

I am making a text adventure game and have to randomise the stats of my hero's enemies.
Is there a way to generate a random whole number from within a percentage range?
Like this: BaseHealth ± 10%, where BaseHealth is a variable.
def randomize_value(value, percent)
bottom = (value * (1 - percent / 100.0)).to_i
up = (value * (1 + percent / 100.0)).to_i
(bottom..up).to_a.sample
end
health = randomize_value(BaseHealth, 10)
This is assuming that health is to be integer.
If BaseHealth is integer,
def take_random base, percent
d = (base * percent / 100.0).to_i
base - d + rand(d * 2)
end
take_random(BaseHealth, 10)
or following Stefan's suggestion,
def take_random base, percent
d = (base * percent / 100.0).to_i
rand(base - d..base + d)
end
take_random(BaseHealth, 10)
I understand what you mean now
You can do this:
BaseHealth = ( rand(BaseHealth * 0.2) + BaseHealth*0.9 ).to_i
This can be accomplished with some basic arithmetic:
TotalHealth = BaseHealth + (BaseHealth * (rand(21)-10)/100)
This will take the BaseHealth and multiply it by a random number 0..20 minus 10, converted to a percent.
Assume BaseHealth = 20:
If rand returns 17, you get 7/100 = .07 so TotalHealth = 21.41
If rand returns 7, you get -7/100 = -.07 so TotalHealth = 18.6

Resources