Pick random element: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: change style of "output". -- ~~~~ |
added qbasic |
||
Line 87: | Line 87: | ||
echo "You feel like a $(rand_element pig donkey unicorn eagle) today"</lang> |
echo "You feel like a $(rand_element pig donkey unicorn eagle) today"</lang> |
||
=={{header|BASIC}}== |
|||
{{works with|QBasic}} |
|||
{{works with|PowerBASIC}} |
|||
Note the use of <code>LBOUND</code> and <code>UBOUND</code>. This is only necessary for arrays where the lower and upper limits aren't known. In this example, we know they are 0 and 10 respectively, and could have hard-coded those numbers. (For that matter, the "random selection" line could've just been entered as <code>x = INT(RND * 11)</code>.) |
|||
<lang qbasic>'setup |
|||
DIM foo(10) AS LONG |
|||
DIM n AS LONG, x AS LONG |
|||
FOR n = LBOUND(foo) TO UBOUND(foo) |
|||
foo(n) = INT(RND*99999) |
|||
NEXT |
|||
RANDOMIZE TIMER |
|||
'random selection |
|||
x = INT(RND * ((UBOUND(foo) - LBOUND(foo)) + 1)) |
|||
'output |
|||
PRINT x, foo(x)</lang> |
|||
See also: [[#Liberty BASIC|Liberty BASIC]], [[#PureBasic|PureBasic]], [[#Run BASIC|Run BASIC]] |
|||
=={{header|C}}== |
=={{header|C}}== |