https://wiki.multitheftauto.com/wiki/Table.getRandomRows?feed=atom&action=history
Table.getRandomRows - Revision history
2024-03-29T10:21:41Z
Revision history for this page on the wiki
MediaWiki 1.39.3
https://wiki.multitheftauto.com/index.php?title=Table.getRandomRows&diff=78257&oldid=prev
IManGaaX: add note
2023-10-18T11:25:50Z
<p>add note</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:25, 18 October 2023</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"><!--'table.random' function already does the job--></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Useful Function}}</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Useful Function}}</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><lowercasetitle></lowercasetitle></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><lowercasetitle></lowercasetitle></div></td></tr>
</table>
IManGaaX
https://wiki.multitheftauto.com/index.php?title=Table.getRandomRows&diff=61056&oldid=prev
CrosRoad95: Created page with "{{Useful Function}} <lowercasetitle></lowercasetitle> __NOTOC__ This function returns the N random unique rows. ==Syntax== <syntaxhighlight lang="lua">table table.getRandomRo..."
2018-12-05T12:11:31Z
<p>Created page with "{{Useful Function}} <lowercasetitle></lowercasetitle> __NOTOC__ This function returns the N random unique rows. ==Syntax== <syntaxhighlight lang="lua">table table.getRandomRo..."</p>
<p><b>New page</b></p><div>{{Useful Function}}<br />
<lowercasetitle></lowercasetitle><br />
__NOTOC__<br />
This function returns the N random unique rows.<br />
<br />
==Syntax==<br />
<syntaxhighlight lang="lua">table table.getRandomRows( table theTable, uint rowsCount )</syntaxhighlight><br />
<br />
===Required Arguments===<br />
* '''theTable''': The table to retrieve the total size of.<br />
* '''rowsCount''': How many rows you want.<br />
<br />
===Returns===<br />
Return N random unique rows.<br />
<br />
==Code==<br />
<section name="Script" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
function table.getRandomRows(table, rowsCount)<br />
if( #table > rowsCount )then<br />
local t = {}<br />
local random<br />
while(rowsCount > 0)do<br />
random = math.random(#table)<br />
if(not t[random] )then<br />
t[random] = random<br />
rowsCount = rowsCount - 1<br />
end<br />
end<br />
local rows = {}<br />
for i,v in pairs(t)do<br />
rows[#rows + 1] = v<br />
end<br />
return rows<br />
else<br />
return table<br />
end<br />
end<br />
<br />
</syntaxhighlight><br />
</section><br />
<br />
==Example==<br />
<section name="Shared" class="both" show="true"><br />
<syntaxhighlight lang="lua"><br />
local tab = {1,2,3,4,5}<br />
iprint( table.getRandomRows(tab, 3) ) -- will print three random rows, example {1,2,3}<br />
</syntaxhighlight><br />
</section><br />
<br />
Author: CrosRoad95<br />
<br />
==See Also==<br />
{{Useful_Functions}}</div>
CrosRoad95