diff --git a/locust/runners.py b/locust/runners.py
index 268f7033..97df507f 100644
--- a/locust/runners.py
+++ b/locust/runners.py
@@ -68,6 +68,7 @@ class LocustRunner(object):
         """
         bucket = []
         weight_sum = sum((locust.weight for locust in self.locust_classes if locust.task_set))
+        residuals = {}
         for locust in self.locust_classes:
             if not locust.task_set:
                 warnings.warn("Notice: Found Locust class (%s) got no task_set. Skipping..." % locust.__name__)
@@ -82,6 +83,21 @@ class LocustRunner(object):
             percent = locust.weight / float(weight_sum)
             num_locusts = int(round(amount * percent))
             bucket.extend([locust for x in xrange(0, num_locusts)])
+            # used to keep track of the amount of rounding was done if we need
+            # to add/remove some instances from bucket
+            residuals[locust] = amount * percent - round(amount * percent)
+        if len(bucket) < amount:
+            # We got too few locust classes in the bucket, so we need to create a few extra locusts,
+            # and we do this by iterating over each of the Locust classes - starting with the one
+            # where the residual from the rounding was the largest - and creating one of each until
+            # we get the correct amount
+            for locust in [l for l, r in sorted(residuals.items(), key=lambda x:x[1], reverse=True)][:amount-len(bucket)]:
+                bucket.append(locust)
+        elif len(bucket) > amount:
+            # We've got too many locusts due to rounding errors so we need to remove some
+            for locust in [l for l, r in sorted(residuals.items(), key=lambda x:x[1])][:len(bucket)-amount]:
+                bucket.remove(locust)
+
         return bucket
 
     def spawn_locusts(self, spawn_count=None, stop_timeout=None, wait=False):

Tests fail to run when providing a small number of clients
Hello,

My current setup in locustfile.py currently looks something like this:
```python
class VolumeTests(object):
      host = 'http://example.com'
      min_wait = 5000
      max_wait = 15000

class ExampleTest(VolumeTests, HttpLocust):
      task_set = MyTaskSet
```
I have 7 of those ExampleTests at the moment, all different types of tests.
In the command line, when I run `locust -c 3 --no-web`, the testing quits and I get the following message:
"Hatching and swarming 0 clients at the rate 1 clients/s..."

However, when I run `locust -c 4 --no-web`, changing the number of clients from 3 to 4, the tests run successfully. 

After some experimenting, it seems like the number of clients you provide must be at least half of the number of tests (i.e. ExampleTest).

Is there something in the locust documentation that I am missing? Or is there something that I am doing wrong? Thanks. 
diff --git a/locust/test/test_runners.py b/locust/test/test_runners.py
index 8a51c75c..14ad50f9 100644
--- a/locust/test/test_runners.py
+++ b/locust/test/test_runners.py
@@ -9,10 +9,12 @@ from locust import events
 from locust.core import Locust, TaskSet, task
 from locust.exception import LocustError
 from locust.rpc import Message
-from locust.runners import LocalLocustRunner, MasterLocustRunner, SlaveNode, STATE_INIT, STATE_HATCHING, STATE_RUNNING, STATE_MISSING
+from locust.runners import LocustRunner, LocalLocustRunner, MasterLocustRunner, SlaveNode, \
+     STATE_INIT, STATE_HATCHING, STATE_RUNNING, STATE_MISSING
 from locust.stats import global_stats, RequestStats
 from locust.test.testcases import LocustTestCase
 
+
 def mocked_rpc_server():
     class MockedRpcServer(object):
         queue = Queue()
@@ -43,6 +45,7 @@ def mocked_rpc_server():
 
     return MockedRpcServer
 
+
 class mocked_options(object):
     def __init__(self):
         self.hatch_rate = 5
@@ -58,6 +61,57 @@ class mocked_options(object):
     def reset_stats(self):
         pass
 
+
+class TestLocustRunner(LocustTestCase):
+    def assert_locust_class_distribution(self, expected_distribution, classes):
+        # Construct a {LocustClass => count} dict from a list of locust classes
+        distribution = {}
+        for locust_class in classes:
+            if not locust_class in distribution:
+                distribution[locust_class] = 0
+            distribution[locust_class] += 1
+        expected_str = str({k.__name__:v for k,v in expected_distribution.items()})
+        actual_str = str({k.__name__:v for k,v in distribution.items()})
+        self.assertEqual(
+            expected_distribution,
+            distribution,
+            "Expected a locust class distribution of %s but found %s" % (
+                expected_str,
+                actual_str,
+            ),
+        )
+
+    def test_weight_locusts(self):
+        maxDiff = 2048
+        class BaseLocust(Locust):
+            class task_set(TaskSet): pass
+        class L1(BaseLocust):
+            weight = 101
+        class L2(BaseLocust):
+            weight = 99
+        class L3(BaseLocust):
+            weight = 100
+
+        runner = LocustRunner([L1, L2, L3], mocked_options())
+        self.assert_locust_class_distribution({L1:10, L2:9, L3:10}, runner.weight_locusts(29))
+        self.assert_locust_class_distribution({L1:10, L2:10, L3:10}, runner.weight_locusts(30))
+        self.assert_locust_class_distribution({L1:11, L2:10, L3:10}, runner.weight_locusts(31))
+
+    def test_weight_locusts_fewer_amount_than_locust_classes(self):
+        class BaseLocust(Locust):
+            class task_set(TaskSet): pass
+        class L1(BaseLocust):
+            weight = 101
+        class L2(BaseLocust):
+            weight = 99
+        class L3(BaseLocust):
+            weight = 100
+
+        runner = LocustRunner([L1, L2, L3], mocked_options())
+        self.assertEqual(1, len(runner.weight_locusts(1)))
+        self.assert_locust_class_distribution({L1:1},  runner.weight_locusts(1))
+
+
 class TestMasterRunner(LocustTestCase):
     def setUp(self):
         global_stats.reset_all()

pip install -e .
parse_log_pytest
requirements.txt
pytest codecov flake8 mock
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
click==8.0.4
codecov==2.1.13
coverage==6.2
dataclasses==0.8
flake8==5.0.4
Flask==2.0.3
gevent==22.10.2
geventhttpclient-wheels==1.3.1.dev3
greenlet==2.0.2
idna==3.10
importlib-metadata==4.2.0
iniconfig==1.1.1
itsdangerous==2.0.1
Jinja2==3.0.3
-e git+https://github.com/locustio/locust.git@40f64e0594d04b883bd68fefa294a4f849d6879c#egg=locustio
MarkupSafe==2.0.1
mccabe==0.7.0
mock==5.2.0
msgpack-python==0.5.6
packaging==21.3
pluggy==1.0.0
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing==3.1.4
pytest==7.0.1
pyzmq==25.1.2
requests==2.27.1
six==1.17.0
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
Werkzeug==2.0.3
zipp==3.6.0
zope.event==4.6
zope.interface==5.5.2

name: locust
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
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - 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=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - click==8.0.4
      - codecov==2.1.13
      - coverage==6.2
      - dataclasses==0.8
      - flake8==5.0.4
      - flask==2.0.3
      - gevent==22.10.2
      - geventhttpclient-wheels==1.3.1.dev3
      - greenlet==2.0.2
      - idna==3.10
      - importlib-metadata==4.2.0
      - iniconfig==1.1.1
      - itsdangerous==2.0.1
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mock==5.2.0
      - msgpack-python==0.5.6
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pyzmq==25.1.2
      - requests==2.27.1
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - werkzeug==2.0.3
      - zipp==3.6.0
      - zope-event==4.6
      - zope-interface==5.5.2
prefix: /opt/conda/envs/locust

locust/test/test_runners.py::TestLocustRunner::test_weight_locusts locust/test/test_runners.py::TestLocustRunner::test_weight_locusts_fewer_amount_than_locust_classes
locust/test/test_runners.py::TestMasterRunner::test_exception_in_task locust/test/test_runners.py::TestMasterRunner::test_exception_is_catched locust/test/test_runners.py::TestMasterRunner::test_master_current_response_times locust/test/test_runners.py::TestMasterRunner::test_master_marks_downed_slaves_as_missing locust/test/test_runners.py::TestMasterRunner::test_master_total_stats locust/test/test_runners.py::TestMasterRunner::test_sends_hatch_data_to_ready_running_hatching_slaves locust/test/test_runners.py::TestMasterRunner::test_slave_connect locust/test/test_runners.py::TestMasterRunner::test_slave_stats_report_median locust/test/test_runners.py::TestMasterRunner::test_spawn_fewer_locusts_than_slaves locust/test/test_runners.py::TestMasterRunner::test_spawn_uneven_locusts locust/test/test_runners.py::TestMasterRunner::test_spawn_zero_locusts locust/test/test_runners.py::TestMessageSerializing::test_message_serialize
locust/runners.py
locust/runners.py