# str.random()

[🔰 JS](https://lochiwei.gitbook.io/web/js) ⟩ [Types](https://lochiwei.gitbook.io/web/js/val/type) ⟩ [String](https://lochiwei.gitbook.io/web/js/val/prim/str) ⟩ [methods](https://lochiwei.gitbook.io/web/js/val/prim/str/method)

{% 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()](https://lochiwei.gitbook.io/web/js/val/prim/num/random/randomint)
  {% endtab %}
  {% endtabs %}
