# Random function

3 replies to this topic

### #1 Desdinova

Desdinova
• Members
• 41 posts

Posted 06 April 2006 - 02:26 PM

This doesn't seem possible with rand();

what I need is, I have say 32 options. I want to select a number between 1 and 32. How should I do this?

### #2 obsidian

obsidian
• Staff Alumni
• 3,202 posts
• LocationSeattle, WA

Posted 06 April 2006 - 02:38 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15).
[/quote]

with that in mind, for your solution, you simply need to do the following:
```\$i = rand(1, 32);
```

You can't win, you can't lose, you can't break even... you can't even get out of the game.

```<?php
while (count(\$life->getQuestions()) > 0)
{   \$life->study(); } ?>```
LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

### #3 Desdinova

Desdinova
• Members
• 41 posts

Posted 06 April 2006 - 02:55 PM

yeah you're right.

php.net explanes it badly. I thought rand(1,30) would create a 30char long random string.

thanks:)

### #4 obsidian

obsidian
• Staff Alumni
• 3,202 posts
• LocationSeattle, WA

Posted 06 April 2006 - 02:58 PM

[!--quoteo(post=362241:date=Apr 6 2006, 10:55 AM:name=Desdinova)--][div class=\'quotetop\']QUOTE(Desdinova @ Apr 6 2006, 10:55 AM) [/div][div class=\'quotemain\'][!--quotec--]
yeah you're right.

php.net explanes it badly. I thought rand(1,30) would create a 30char long random string.

thanks:)
[/quote]

the manual definitely can be difficult to understand at times... that's why we're here ;-)
You can't win, you can't lose, you can't break even... you can't even get out of the game.

```<?php
while (count(\$life->getQuestions()) > 0)
{   \$life->study(); } ?>```
LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users