> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/prim/str/method/.random.md).

# str.random()

[🔰 JS](/web/js.md) ⟩ [Types](/web/js/val/type.md) ⟩ [String](/web/js/val/prim/str.md) ⟩ [methods](/web/js/val/prim/str/method.md)

{% tabs %}
{% tab title="string.random" %}

```javascript
// ⭐️ string.random()
// ⭐️ Note: this may not work well with Unicode❗️ 
String.prototype.random = function(){
    return this[randomInt(this.length)];
}

// ⭐️ randomChar(str)
// ⭐️ Note: this may not work well with Unicode❗️
export function randomChar(str) {
    return str[randomInt(0, str.length - 1)];
}
```

{% endtab %}

{% tab title="⬆️ 相依" %}

* [randomInt()](/web/js/val/prim/num/random/randomint.md)
  {% endtab %}
  {% endtabs %}
