Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/container.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/container.py	(revision 8409)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/container.py	(revision 8410)
@@ -20,7 +20,13 @@
 """
 import grok
+from thread import allocate_lock
+from transaction import commit
+from zope.component import getUtility
 from waeup.kofa.students.interfaces import (
-    IStudentsContainer, IStudent)
+    IStudentsContainer, IStudent, IStudentsUtils)
+from waeup.kofa.utils.helpers import attrs_to_fields
 from waeup.kofa.utils.logger import Logger
+
+lock = allocate_lock() # a lock object to lock threads.
 
 class StudentsContainer(grok.Container, Logger):
@@ -30,4 +36,29 @@
 
     grok.implements(IStudentsContainer)
+
+    _curr_stud_id = 10 ** 6
+
+    @property
+    def unique_student_id(self):
+        """A unique student id.
+
+        The student id returned is guaranteed to be unique. It
+        consists of some prefix (normally a single letter) followed by
+        a number with at least 7 digits.
+
+        Once a student id was issued, it won't be issued again.
+
+        Obtaining a student id is currently not thread-safe but can be
+        made easily by enabling commented lines.
+        """
+        prefix = getUtility(IStudentsUtils).STUDENT_ID_PREFIX
+
+        # lock.acquire() # lock data
+        new_id = u'%s%s' % (prefix, self._curr_stud_id)
+        self._curr_stud_id += 1
+        # self._p_changed = True
+        # commit()
+        # lock.release() # end of lock
+        return new_id
 
     def archive(self, id=None):
@@ -55,2 +86,4 @@
                 ob_class, target, comment))
         return
+
+StudentsContainer = attrs_to_fields(StudentsContainer)
Index: /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 8409)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 8410)
@@ -95,11 +95,8 @@
     return tag1 + u'%s</font>' % text
 
-def generate_student_id(students,letter):
-    if letter == '?':
-        letter= r().choice('ABCDEFGHKLMNPQRSTUVWXY')
-    sid = u"%c%d" % (letter,r().randint(99999,1000000))
-    while sid in students.keys():
-        sid = u"%c%d" % (letter,r().randint(99999,1000000))
-    return sid
+def generate_student_id(students, letter='?'):
+    students = grok.getSite()['students']
+    new_id = students.unique_student_id
+    return new_id
 
 def set_up_widgets(view, ignore_request=False):
@@ -393,2 +390,6 @@
     SEPARATORS_DICT = {
         }
+
+    #: A prefix used when generating new student ids. Each student id will
+    #: start with this string. The default is 'K' for ``Kofa``.
+    STUDENT_ID_PREFIX = u'K'
