Я не знаком с тем, как работает лотерея. Я предполагаю, что все номера, включая дополнительный номер, взяты из одного набора без замены. Если это правда, этот код должен помочь вам:
import random
numbers = list(range(1, 51)) # include 50
random.shuffle(numbers)
print(numbers[:6]) # pick the first 6 numbers (5 + 1 additional number) in the randomize list
Если ваш дополнительный номер взят из отдельного набора, сделайте следующее:
import random
numbers = list(range(1, 51)) # include 50
random.shuffle(numbers)
# pick the first 5 from the randomized list:
picks = numbers[:5]
# select from remaining numbers those that are less than or equal to 20:
picks.append(random.choice([n for n in numbers[5:] if n <= 20]))
print(picks)
See this example : http://www.exampledepot.com/egs/javax.swing.table/Vis.html
update: the link is now obsolete, here is the code (from http://smi-protege.stanford.edu/repos/protege/protege-core/trunk/src/edu/stanford/smi/protege/util/ComponentUtilities.java )
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
if (!(table.getParent() instanceof JViewport)) {
return;
}
JViewport viewport = (JViewport)table.getParent();
// This rectangle is relative to the table where the
// northwest corner of cell (0,0) is always (0,0).
Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
// The location of the viewport relative to the table
Point pt = viewport.getViewPosition();
// Translate the cell location so that it is relative
// to the view, assuming the northwest corner of the
// view is (0,0)
rect.setLocation(rect.x-pt.x, rect.y-pt.y);
table.scrollRectToVisible(rect);
// Scroll the area into view
//viewport.scrollRectToVisible(rect);
}
JList внутренне использовать scrollRectToVisible и указать координаты для прокрутки. Думаю, вам придется перекодировать аналогичную функциональность для JTable.