PDA

Просмотр полной версии : Как получить случайное число


soniks
14.02.2003, 11:42
Как получить случайное число:
1) на промежутке (например от 1 до 100).
2) или из группы разных чисел (не попорядку и нет прогрессии и закономерностей (например 2, 188, 5, 34, 1000).

SPV
14.02.2003, 11:52
Math.random
array[Math.random]

soniks
14.02.2003, 11:56
что-то не пойму. Например переменной x надо присвоить случайное число от 1 до 100 как скрипт выглядет?

SPV
14.02.2003, 12:18
F1:
------------------------------------------------------------------------------
Math.random

Syntax

Math.random();
Arguments

None.

Description

Method; returns a pseudo-random number between 0.0 and 1.0.

Player

Flash 5 or later. In the Flash 4 Player, the methods and properties of the Math object are emulated using approximations and may not be as accurate as the non-emulated math functions supported by the Flash 5 Player.

See also

random
------------------------------------------------------------
random

Syntax

random();
Arguments

value The highest integer for which random will return a value.

Description

Function; returns a random integer between 0 and the integer specified in the value argument.

Player

Flash 4. This function is deprecated in Flash 5; use of the Math.random method is recommended.

Example

The following use of random returns a value of 0, 1, 2, 3, or 4:

random(5);
See also

Math.random
--------------------------------

x = 1+random(100);

x = 1+int(Math.random()*100);

x = 1+Math.floor(Math.random()*100);

lexass
14.02.2003, 12:37
Math.random()
Method; returns n, where 0 <= n < 1.

||

Flash Player 4. This function is deprecated in Flash 5; use of the Math.random method is recommended.
Usage
random(value)
Example
The following use of random returns a value of 0, 1, 2, 3, or 4:
random(5);