1. I am tired, so I am not sure if it is my math or coding that is the problem here...
Code:
```	r1 = (Math.random()*511)+1;
if (256 < r1 < 512)
{
int1 = 1;
}
else if (128 < r1 < 256)
{
int1 = 2;
}
else if (64 < r1 < 128)
{
int1 = 3;
}
else if (32 < r1 < 64)
{
int1 = 4;
}
else if (16 < r1 < 32)
{
int1 = 5;
}
else if (8 < r1 < 16)
{
int1 = 6;
}
else if (4 < r1 < 8)
{
int1 = 7;
}
else if (2 < r1 < 4)
{
int1 = 8;
}
else if (1 < r1 < 2)
{
int1 = 9;
}```
This script generates a random number (between 1 and 512), then there are a number of if statements which have differing chances of being true (1/2, 1/4, 1/8, 1/16, 1/32, 1/64 etc.).

But...

It doesn't work, it just returns 1 each time.

2.

3. Try this:
Code:
```	r1 = (Math.random()*511)+1;
if (r1 >= 256) {
int1 = 1;
} else if (r1 >= 128 ) {
int1 = 2;
} else if (r1 >= 64) {
int1 = 3;
} else if (r1 >= 32) {
int1 = 4;
} else if (r1 >= 16) {
int1 = 5;
} else if (r1 >= 8) {
int1 = 6;
} else if (r1 >= 4) {
int1 = 7;
} else if (r1 >= 2) {
int1 = 8;
} else {
int1 = 9;
}```

4. They're all powers of 2...surely sqrt or something similar would be useful?

5. Thanks

6. Here's a mathematical increasing probability chooser (you can set the number of choices and increasing probability of each choice:
Code:
```<script>
var number = 9;    //number of possibilities you want
var scale = 2;     //scale of increasing possibility per increment.
var seed = Math.pow(scale, number);  //random number seed
var pick = Math.random() * seed + 1;
for (var i = (number - 1); i >= 0; i --) {
if (pick >= Math.pow(scale, i)) {
int1 = number - i;
break;
}
}
</script>```
EDIT: made some minor mods to it. This will return the same values as the option above

7. Thanks

Its for my game. I screwed it all up because the biggest probability was 1/512, cube it (what you would need to win, I am not telling you what my game is yet though ) and it becomes 1/134 217 728 !!!

So I need a re-think

8. The last post I made allows you to increase probabilities by a cubic degree... just change the "scale" variable to 3.

9. Sounds like a log problem.

Code:
```var Max=512;
var Base=2;
var RandNum = Math.round(Math.random()*512);
var Power = Math.log(RandNum)/Math.log(Base);
intl = 9-Math.round(Power);```
You might want to replace Math.round with Math.floor

10. Very nice solution. Logarithms are what I was missing. Damn you :-P

11. I do Physics, so it was kind of duh!

Page 1 of 2 1 2 Last