Cassandra RandomPartitioner Tokenizing


So I'm creating a new cluster, and after setting up I needed to get my tokens.  As we're told in


Token selection:

Using a strong hash function means RandomPartitioner keys will, on average, be evenly spread across the Token space, but you can still have imbalances if your Tokens do not divide up the range evenly, so you should specify InitialToken to your first nodes as i * (2**127 / N) for i = 0 .. N-1. In Cassandra 0.7, you should specify initial_token in cassandra.yaml.  

Here's a nice simple code snippet to figure out your RandomPartitioner tokens based on the size of your cluster:


#! /usr/bin/python


#nodes = int(raw_input( "How many nodes?" ))

import sys


def tokens(nodes):

    for i in range(1, nodes + 1):

        print (i * (2 ** 127 - 1) / nodes)



This should give something like this:


[root@cassandra06 conf]# ./ 6









The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.
Website by Digital Loom