jkowalleck: mergeds some other shit i did meanwhile.
now there are conflicts .... 
will research later
jkowalleck: closes #122
diff --git a/src/nichtparasoup-server.py b/src/nichtparasoup-server.py
index f6c3be0..2040b53 100644
--- a/src/nichtparasoup-server.py
+++ b/src/nichtparasoup-server.py
@@ -51,7 +51,7 @@ if __name__ == "__main__":
     nichtparasoup = NichtParasoup()
 
     # TODO: write this foo based on some proper settings
-    nichtparasoup.add_imagecrawler(DummyCrawler('dummy1'), 1)
+    nichtparasoup.add_imagecrawler(DummyCrawler('dummy1'), 0.5)
     nichtparasoup.add_imagecrawler(PicsumCrawler('800/600'), 1)
 
     webserver = WebServer(nichtparasoup)
diff --git a/src/nichtparasoup/nichtparasoup.py b/src/nichtparasoup/nichtparasoup.py
index 8aab034..b3fff3b 100644
--- a/src/nichtparasoup/nichtparasoup.py
+++ b/src/nichtparasoup/nichtparasoup.py
@@ -1,7 +1,7 @@
 __all__ = ["NichtParasoup", "Crawler", "CrawlerWeight", "Crawlers", "Blacklist"]
 
-from typing import Any, Union, Set, Callable, Optional
-from random import choice as random_choice
+from typing import Any, Union, Set, Callable, Optional, List
+from random import choice as random_choice, uniform as random_float
 
 from .imagecrawler import Images, Image, ImageUri, ImageCrawler
 
@@ -57,15 +57,19 @@ class Crawler(object):
         return image
 
 
-class Crawlers(Set[Crawler]):
+class Crawlers(List[Crawler]):
+
+    def _random_weight(self) -> CrawlerWeight:
+        return random_float(0, sum(crawler.weight for crawler in self))
 
     def get_random(self) -> Optional[Crawler]:
-        if not self:
-            return None
-        crawlers = list(self)
-        # TODO: add weighted random
-        crawler = random_choice(crawlers)  # type: Crawler
-        return crawler
+        cum_weight_goal = self._random_weight()
+        cum_weight = 0  # type: CrawlerWeight
+        for crawler in self:
+            cum_weight += crawler.weight
+            if cum_weight >= cum_weight_goal:
+                return crawler
+        return None
 
 
 class NichtParasoup(object):
@@ -83,10 +87,11 @@ class NichtParasoup(object):
         self.blacklist.add(image.uri)
 
     def add_imagecrawler(self, imagecrawler: ImageCrawler, weight: CrawlerWeight) -> None:
-        self.crawlers.add(Crawler(
-            imagecrawler, weight,
-            self._is_image_not_in_blacklist, self._add_image_to_blacklist
-        ))
+        if imagecrawler not in (crawler.imagecrawler for crawler in self.crawlers):
+            self.crawlers.append(Crawler(
+                imagecrawler, weight,
+                self._is_image_not_in_blacklist, self._add_image_to_blacklist
+            ))
 
     def get_random_image(self) -> Optional[Image]:
         crawler = self.crawlers.get_random()
diff --git a/tox.ini b/tox.ini
index e27408e..6278c0d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,7 +19,10 @@ passenv =
 commands =
     mypy
     flake8
-    coverage run -m pytest
+    coverage run -m pytest -v
     coverage report -m
     # codecov failed a lot on travis. so codecov os not `--required`
     codecov: codecov -e TOXENV
+
+[testenv:interactive]
+commands = python -i

2.0-dev weighted randomness support
diff --git a/testing/nichtparasoup_test/__init__.py b/testing/nichtparasoup_test/__init__.py
new file mode 100644
index 0000000..adb4ee2
--- /dev/null
+++ b/testing/nichtparasoup_test/__init__.py
@@ -0,0 +1,8 @@
+from nichtparasoup.imagecrawler import ImageCrawler, Images
+
+
+class _EmptyImageCrawler(ImageCrawler):
+    """ imagecrawler that finds nothing. use it for mocking ... """
+
+    def crawl(self) -> Images:
+        return Images()
diff --git a/testing/nichtparasoup/crawler_test.py b/testing/nichtparasoup_test/crawler_test.py
similarity index 87%
rename from testing/nichtparasoup/crawler_test.py
rename to testing/nichtparasoup_test/crawler_test.py
index d7b332b..6a50f35 100644
--- a/testing/nichtparasoup/crawler_test.py
+++ b/testing/nichtparasoup_test/crawler_test.py
@@ -2,14 +2,9 @@ import unittest
 from unittest.mock import MagicMock
 
 from nichtparasoup.nichtparasoup import Crawler
-from nichtparasoup.imagecrawler import Image, Images, ImageCrawler
+from nichtparasoup.imagecrawler import Image, Images
 
-
-class _EmptyImageCrawler(ImageCrawler):
-    """ imagecrawler that finds nothing. use it for mocking ... """
-
-    def crawl(self) -> Images:
-        return Images()
+from . import _EmptyImageCrawler
 
 
 class CrawlerTest(unittest.TestCase):
diff --git a/testing/nichtparasoup_test/crawlers_test.py b/testing/nichtparasoup_test/crawlers_test.py
new file mode 100644
index 0000000..83a34ac
--- /dev/null
+++ b/testing/nichtparasoup_test/crawlers_test.py
@@ -0,0 +1,37 @@
+import unittest
+from unittest.mock import MagicMock
+from ddt import ddt, data as ddt_data, unpack as ddt_unpack  # type: ignore
+
+from typing import List, Optional
+
+from nichtparasoup.nichtparasoup import Crawler, Crawlers, CrawlerWeight
+
+from . import _EmptyImageCrawler
+
+
+@ddt
+class CrawlersTest(unittest.TestCase):
+
+    @ddt_data(  # type: ignore
+        ([], 0, None), ([], 1, None),
+        ([1], 0, 0), ([1], 0.5, 0), ([1], 1, 0),
+        ([1, 2], 0, 0), ([0.7, 2], 0.5, 0), ([1, 2], 1.001, 1), ([1, 2], 3, 1),
+    )
+    @ddt_unpack  # type: ignore
+    def test_get_random(self, weights: List[CrawlerWeight],
+                        weight_rnd: CrawlerWeight, expected_choice: Optional[int]
+                        ) -> None:
+        # arrange
+        crawlers = Crawlers()
+        crawlers._random_weight = MagicMock(return_value=weight_rnd)  # type: ignore
+        for weight in weights:
+            crawlers.append(Crawler(_EmptyImageCrawler('test'), weight))
+
+        # act
+        random_crawler = crawlers.get_random()
+
+        # assert
+        if expected_choice is None:
+            self.assertIsNone(random_crawler, "did not expect choice")
+        else:
+            self.assertIs(random_crawler, crawlers[expected_choice], "did expect different coice")
diff --git a/testing/nichtparasoup/imagecrawler/dummy_test.py b/testing/nichtparasoup_test/imagecrawler_test/dummy_test.py
similarity index 100%
rename from testing/nichtparasoup/imagecrawler/dummy_test.py
rename to testing/nichtparasoup_test/imagecrawler_test/dummy_test.py
diff --git a/testing/nichtparasoup/imagecrawler/image_test.py b/testing/nichtparasoup_test/imagecrawler_test/image_test.py
similarity index 100%
rename from testing/nichtparasoup/imagecrawler/image_test.py
rename to testing/nichtparasoup_test/imagecrawler_test/image_test.py
diff --git a/testing/nichtparasoup/nichtparasoup_test.py b/testing/nichtparasoup_test/nichtparasoup_test.py
similarity index 85%
rename from testing/nichtparasoup/nichtparasoup_test.py
rename to testing/nichtparasoup_test/nichtparasoup_test.py
index 71bb9fb..8b6537f 100644
--- a/testing/nichtparasoup/nichtparasoup_test.py
+++ b/testing/nichtparasoup_test/nichtparasoup_test.py
@@ -1,14 +1,9 @@
 import unittest
 
 from nichtparasoup.nichtparasoup import NichtParasoup
-from nichtparasoup.imagecrawler import Images, Image, ImageCrawler
+from nichtparasoup.imagecrawler import Image
 
-
-class _EmptyImageCrawler(ImageCrawler):
-    """ imagecrawler that finds nothing. use it for mocking ... """
-
-    def crawl(self) -> Images:
-        return Images()
+from . import _EmptyImageCrawler
 
 
 class NichtParasoupTest(unittest.TestCase):
@@ -46,9 +41,11 @@ class NichtParasoupTest(unittest.TestCase):
 
         # act
         nichtparasoup.add_imagecrawler(imagecrawler, 1)
+        nichtparasoup.add_imagecrawler(imagecrawler, 1)
 
         # assert
         self.assertIn(
             imagecrawler,
             (crawler.imagecrawler for crawler in nichtparasoup.crawlers),
             'expected imagecrawler in list')
+        self.assertEqual(1, len(nichtparasoup.crawlers))

pip install -e .[testing]
parse_log_pytest
requirements.txt
pytest coverage flake8 mypy ddt pep8-naming
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
coverage==7.8.0
ddt==1.7.2
exceptiongroup==1.2.2
flake8==7.2.0
iniconfig==2.1.0
MarkupSafe==3.0.2
mccabe==0.7.0
mypy==1.15.0
mypy-extensions==1.0.0
-e git+https://github.com/k4cg/nichtparasoup.git@d9dda8d8b1e9a96b5b16c4c989a232de472c3f77#egg=nichtparasoup
packaging==24.2
pep8-naming==0.14.1
pluggy==1.5.0
pycodestyle==2.13.0
pyflakes==3.3.2
pytest==8.3.5
tomli==2.2.1
typing_extensions==4.13.0
Werkzeug==3.1.3

name: nichtparasoup
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - coverage==7.8.0
      - ddt==1.7.2
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - iniconfig==2.1.0
      - markupsafe==3.0.2
      - mccabe==0.7.0
      - mypy==1.15.0
      - mypy-extensions==1.0.0
      - packaging==24.2
      - pep8-naming==0.14.1
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.2
      - pytest==8.3.5
      - tomli==2.2.1
      - typing-extensions==4.13.0
      - werkzeug==3.1.3
prefix: /opt/conda/envs/nichtparasoup

testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_3___1___0__0_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_4___1___0_5__0_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_5___1___1__0_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_6___1__2___0__0_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_7___0_7__2___0_5__0_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_8___1__2___1_001__1_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_9___1__2___3__1_ testing/nichtparasoup_test/nichtparasoup_test.py::NichtParasoupTest::test_add_imagerawler
testing/nichtparasoup_test/crawler_test.py::CrawlerTest::test_crawl testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_1______0__None_ testing/nichtparasoup_test/crawlers_test.py::CrawlersTest::test_get_random_2______1__None_ testing/nichtparasoup_test/imagecrawler_test/dummy_test.py::CrawlerDummyTest::test_crawl testing/nichtparasoup_test/imagecrawler_test/image_test.py::ImageTest::test_uri_is_hash testing/nichtparasoup_test/nichtparasoup_test.py::NichtParasoupTest::test__add_image_to_blacklist testing/nichtparasoup_test/nichtparasoup_test.py::NichtParasoupTest::test__is_image_not_in_blacklist
src/nichtparasoup-server.py tox.ini src/nichtparasoup/nichtparasoup.py
src/nichtparasoup-server.py tox.ini src/nichtparasoup/nichtparasoup.py