Files
oraset/docs/site/en/libraries/math/index.html
T
2026-04-24 21:54:58 +08:00

1062 lines
32 KiB
HTML

<!doctype html>
<html lang="zh" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Oraset 编程语言文档">
<meta name="author" content="Oraset Team">
<link rel="canonical" href="https://oraset.org/en/libraries/math/">
<link rel="icon" href="../../../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.6">
<title>Math Library - Oraset 编程语言</title>
<link rel="stylesheet" href="../../../assets/stylesheets/main.484c7ddc.min.css">
<link rel="stylesheet" href="../../../assets/stylesheets/palette.ab4e12ef.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
<script>__md_scope=new URL("../../..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="default" data-md-color-primary="orange" data-md-color-accent="orange">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#math-library" class="md-skip">
跳转至
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="页眉">
<a href="../../.." title="Oraset 编程语言" class="md-header__button md-logo" aria-label="Oraset 编程语言" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Oraset 编程语言
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Math Library
</span>
</div>
</div>
</div>
<form class="md-header__option" data-md-component="palette">
<input class="md-option" data-md-color-media="" data-md-color-scheme="default" data-md-color-primary="orange" data-md-color-accent="orange" aria-hidden="true" type="radio" name="__palette" id="__palette_0">
<input class="md-option" data-md-color-media="" data-md-color-scheme="slate" data-md-color-primary="deep-orange" data-md-color-accent="deep-orange" aria-hidden="true" type="radio" name="__palette" id="__palette_1">
</form>
<script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="搜索" placeholder="搜索" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="查找">
<button type="reset" class="md-search__icon md-icon" title="清空当前内容" aria-label="清空当前内容" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
<div class="md-search__suggest" data-md-component="search-suggest"></div>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
正在初始化搜索引擎
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<nav class="md-tabs" aria-label="标签" data-md-component="tabs">
<div class="md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item">
<a href="../../.." class="md-tabs__link">
首页
</a>
</li>
<li class="md-tabs__item">
<a href="../../../tutorial/quickstart/" class="md-tabs__link">
入门教程
</a>
</li>
<li class="md-tabs__item">
<a href="../../../libraries/math/" class="md-tabs__link">
库参考
</a>
</li>
</ul>
</div>
</nav>
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="导航栏" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="../../.." title="Oraset 编程语言" class="md-nav__button md-logo" aria-label="Oraset 编程语言" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg>
</a>
Oraset 编程语言
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../.." class="md-nav__link">
<span class="md-ellipsis">
首页
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_2" >
<label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
<span class="md-ellipsis">
入门教程
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_2">
<span class="md-nav__icon md-icon"></span>
入门教程
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../tutorial/quickstart/" class="md-nav__link">
<span class="md-ellipsis">
快速开始
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_3" >
<label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
<span class="md-ellipsis">
库参考
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_3">
<span class="md-nav__icon md-icon"></span>
库参考
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../../../libraries/math/" class="md-nav__link">
<span class="md-ellipsis">
数学库
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary" aria-label="目录">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
目录
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#introduction" class="md-nav__link">
<span class="md-ellipsis">
Introduction
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#import" class="md-nav__link">
<span class="md-ellipsis">
Import
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#function-reference" class="md-nav__link">
<span class="md-ellipsis">
Function Reference
</span>
</a>
<nav class="md-nav" aria-label="Function Reference">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#basic-math-functions" class="md-nav__link">
<span class="md-ellipsis">
Basic Math Functions
</span>
</a>
<nav class="md-nav" aria-label="Basic Math Functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mathabsx" class="md-nav__link">
<span class="md-ellipsis">
math.abs(x)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathsqrtx" class="md-nav__link">
<span class="md-ellipsis">
math.sqrt(x)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathpowx-y" class="md-nav__link">
<span class="md-ellipsis">
math.pow(x, y)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#trigonometric-functions" class="md-nav__link">
<span class="md-ellipsis">
Trigonometric Functions
</span>
</a>
<nav class="md-nav" aria-label="Trigonometric Functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mathsinx" class="md-nav__link">
<span class="md-ellipsis">
math.sin(x)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathcosx" class="md-nav__link">
<span class="md-ellipsis">
math.cos(x)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathtanx" class="md-nav__link">
<span class="md-ellipsis">
math.tan(x)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#math-constants" class="md-nav__link">
<span class="md-ellipsis">
Math Constants
</span>
</a>
<nav class="md-nav" aria-label="Math Constants">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mathpi" class="md-nav__link">
<span class="md-ellipsis">
math.pi()
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathe" class="md-nav__link">
<span class="md-ellipsis">
math.e()
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#extremum-functions" class="md-nav__link">
<span class="md-ellipsis">
Extremum Functions
</span>
</a>
<nav class="md-nav" aria-label="Extremum Functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mathmaxargs" class="md-nav__link">
<span class="md-ellipsis">
math.max(...args)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathminargs" class="md-nav__link">
<span class="md-ellipsis">
math.min(...args)
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#random-number-functions" class="md-nav__link">
<span class="md-ellipsis">
Random Number Functions
</span>
</a>
<nav class="md-nav" aria-label="Random Number Functions">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#mathrandom" class="md-nav__link">
<span class="md-ellipsis">
math.random()
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#mathrandinta-b" class="md-nav__link">
<span class="md-ellipsis">
math.randint(a, b)
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#example-code" class="md-nav__link">
<span class="md-ellipsis">
Example Code
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="math-library">Math Library<a class="headerlink" href="#math-library" title="Permanent link">&para;</a></h1>
<h2 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link">&para;</a></h2>
<p>The math library (<code>@math</code>) provides a range of mathematical functions, including basic operations, trigonometric functions, random number generation, and more.</p>
<h2 id="import">Import<a class="headerlink" href="#import" title="Permanent link">&para;</a></h2>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>@math;
</code></pre></div></td></tr></table></div>
<h2 id="function-reference">Function Reference<a class="headerlink" href="#function-reference" title="Permanent link">&para;</a></h2>
<h3 id="basic-math-functions">Basic Math Functions<a class="headerlink" href="#basic-math-functions" title="Permanent link">&para;</a></h3>
<h4 id="mathabsx">math.abs(x)<a class="headerlink" href="#mathabsx" title="Permanent link">&para;</a></h4>
<p>Calculate absolute value.</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Number</p>
<p><strong>Returns:</strong>
- Absolute value of the number</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`abs(-123) = `, math.abs(-123)); // Output: 123
</code></pre></div></td></tr></table></div>
<h4 id="mathsqrtx">math.sqrt(x)<a class="headerlink" href="#mathsqrtx" title="Permanent link">&para;</a></h4>
<p>Calculate square root.</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Non-negative number</p>
<p><strong>Returns:</strong>
- Square root value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`sqrt(16) = `, math.sqrt(16)); // Output: 4
</code></pre></div></td></tr></table></div>
<h4 id="mathpowx-y">math.pow(x, y)<a class="headerlink" href="#mathpowx-y" title="Permanent link">&para;</a></h4>
<p>Calculate power operation.</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Base
- <code>y</code> - Exponent</p>
<p><strong>Returns:</strong>
- x raised to the power of y</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`pow(2, 3) = `, math.pow(2, 3)); // Output: 8
</code></pre></div></td></tr></table></div>
<h3 id="trigonometric-functions">Trigonometric Functions<a class="headerlink" href="#trigonometric-functions" title="Permanent link">&para;</a></h3>
<h4 id="mathsinx">math.sin(x)<a class="headerlink" href="#mathsinx" title="Permanent link">&para;</a></h4>
<p>Calculate sine value (in degrees).</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Angle in degrees</p>
<p><strong>Returns:</strong>
- Sine value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`sin(90) = `, math.sin(90)); // Output: 1
</code></pre></div></td></tr></table></div>
<h4 id="mathcosx">math.cos(x)<a class="headerlink" href="#mathcosx" title="Permanent link">&para;</a></h4>
<p>Calculate cosine value (in degrees).</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Angle in degrees</p>
<p><strong>Returns:</strong>
- Cosine value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`cos(0) = `, math.cos(0)); // Output: 1
</code></pre></div></td></tr></table></div>
<h4 id="mathtanx">math.tan(x)<a class="headerlink" href="#mathtanx" title="Permanent link">&para;</a></h4>
<p>Calculate tangent value (in degrees).</p>
<p><strong>Parameters:</strong>
- <code>x</code> - Angle in degrees</p>
<p><strong>Returns:</strong>
- Tangent value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`tan(45) = `, math.tan(45)); // Output: 1
</code></pre></div></td></tr></table></div>
<h3 id="math-constants">Math Constants<a class="headerlink" href="#math-constants" title="Permanent link">&para;</a></h3>
<h4 id="mathpi">math.pi()<a class="headerlink" href="#mathpi" title="Permanent link">&para;</a></h4>
<p>Return the value of pi (π).</p>
<p><strong>Parameters:</strong> None</p>
<p><strong>Returns:</strong>
- Value of π (approximately 3.14159...)</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`π = `, math.pi()); // Output: 3.141592653589793
</code></pre></div></td></tr></table></div>
<h4 id="mathe">math.e()<a class="headerlink" href="#mathe" title="Permanent link">&para;</a></h4>
<p>Return the value of Euler's number (e).</p>
<p><strong>Parameters:</strong> None</p>
<p><strong>Returns:</strong>
- Value of e (approximately 2.71828...)</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`e = `, math.e()); // Output: 2.718281828459045
</code></pre></div></td></tr></table></div>
<h3 id="extremum-functions">Extremum Functions<a class="headerlink" href="#extremum-functions" title="Permanent link">&para;</a></h3>
<h4 id="mathmaxargs">math.max(...args)<a class="headerlink" href="#mathmaxargs" title="Permanent link">&para;</a></h4>
<p>Calculate the maximum of multiple numbers.</p>
<p><strong>Parameters:</strong>
- <code>...args</code> - Multiple numbers</p>
<p><strong>Returns:</strong>
- Maximum value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`max(10, 5, 20) = `, math.max(10, 5, 20)); // Output: 20
</code></pre></div></td></tr></table></div>
<h4 id="mathminargs">math.min(...args)<a class="headerlink" href="#mathminargs" title="Permanent link">&para;</a></h4>
<p>Calculate the minimum of multiple numbers.</p>
<p><strong>Parameters:</strong>
- <code>...args</code> - Multiple numbers</p>
<p><strong>Returns:</strong>
- Minimum value</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`min(10, 5, 20) = `, math.min(10, 5, 20)); // Output: 5
</code></pre></div></td></tr></table></div>
<h3 id="random-number-functions">Random Number Functions<a class="headerlink" href="#random-number-functions" title="Permanent link">&para;</a></h3>
<h4 id="mathrandom">math.random()<a class="headerlink" href="#mathrandom" title="Permanent link">&para;</a></h4>
<p>Generate a random number between 0 and 1.</p>
<p><strong>Parameters:</strong> None</p>
<p><strong>Returns:</strong>
- Random float between 0 and 1</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`random() = `, math.random()); // Output: 0.123456...
</code></pre></div></td></tr></table></div>
<h4 id="mathrandinta-b">math.randint(a, b)<a class="headerlink" href="#mathrandinta-b" title="Permanent link">&para;</a></h4>
<p>Generate a random integer within a specified range.</p>
<p><strong>Parameters:</strong>
- <code>a</code> - Minimum value
- <code>b</code> - Maximum value</p>
<p><strong>Returns:</strong>
- Random integer between a and b (inclusive)</p>
<p><strong>Example:</strong></p>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><code>show(`randint(1, 100) = `, math.randint(1, 100)); // Output: 42
</code></pre></div></td></tr></table></div>
<h2 id="example-code">Example Code<a class="headerlink" href="#example-code" title="Permanent link">&para;</a></h2>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span>
<span class="normal">17</span>
<span class="normal">18</span>
<span class="normal">19</span>
<span class="normal">20</span>
<span class="normal">21</span>
<span class="normal">22</span>
<span class="normal">23</span></pre></div></td><td class="code"><div><pre><span></span><code>@math;
!! Basic operations
show(`abs(-123) = `, math.abs(-123));
show(`sqrt(16) = `, math.sqrt(16));
show(`pow(2, 3) = `, math.pow(2, 3));
!! Trigonometric functions
show(`sin(90) = `, math.sin(90));
show(`cos(0) = `, math.cos(0));
show(`tan(45) = `, math.tan(45));
!! Math constants
show(`π = `, math.pi());
show(`e = `, math.e());
!! Extremum
show(`max(10, 5, 20) = `, math.max(10, 5, 20));
show(`min(10, 5, 20) = `, math.min(10, 5, 20));
!! Random numbers
show(`random() = `, math.random());
show(`randint(1, 100) = `, math.randint(1, 100));
</code></pre></div></td></tr></table></div>
</article>
</div>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
回到页面顶部
</button>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
<div class="md-social">
<a href="https://github.com/oraset/oraset" target="_blank" rel="noopener" title="github.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg>
</a>
<a href="https://bbs.ecuil.com" target="_blank" rel="noopener" title="bbs.ecuil.com" class="md-social__link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M5.8 309.7C2 292.7 0 275.5 0 258.3 0 135 99.8 35 223.1 35c16.6 0 33.3 2 49.3 5.5C149 87.5 51.9 186 5.8 309.7m392.9-189.2C385 103 369 87.8 350.9 75.2c-149.6 44.3-266.3 162.1-309.7 312 12.5 18.1 28 35.6 45.2 49 43.1-151.3 161.2-271.7 312.3-315.7m15.8 252.7c15.2-25.1 25.4-53.7 29.5-82.8-79.4 42.9-145 110.6-187.6 190.3 30-4.4 58.9-15.3 84.6-31.3 35 13.1 70.9 24.3 107 33.6-9.3-36.5-20.4-74.5-33.5-109.8m29.7-145.5c-2.6-19.5-7.9-38.7-15.8-56.8C290.5 216.7 182 327.5 137.1 466c18.1 7.6 37 12.5 56.6 15.2C240 367.1 330.5 274.4 444.2 227.7"/></svg>
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"annotate": null, "base": "../../..", "features": ["navigation.tabs", "navigation.sections", "navigation.expand", "navigation.top", "search.suggest", "search.highlight"], "search": "../../../assets/javascripts/workers/search.2c215733.min.js", "tags": null, "translations": {"clipboard.copied": "\u5df2\u590d\u5236", "clipboard.copy": "\u590d\u5236", "search.result.more.one": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.more.other": "\u5728\u8be5\u9875\u4e0a\u8fd8\u6709 # \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.none": "\u6ca1\u6709\u627e\u5230\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.one": "\u627e\u5230 1 \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.other": "# \u4e2a\u7b26\u5408\u6761\u4ef6\u7684\u7ed3\u679c", "search.result.placeholder": "\u952e\u5165\u4ee5\u5f00\u59cb\u641c\u7d22", "search.result.term.missing": "\u7f3a\u5c11", "select.version": "\u9009\u62e9\u5f53\u524d\u7248\u672c"}, "version": null}</script>
<script src="../../../assets/javascripts/bundle.79ae519e.min.js"></script>
</body>
</html>