<commit_before>import helpers from './helpers/helpers'
import { beliefs } from './config'
import { users } from './fixedData'
import { scaleOrdinal, schemeCategory10 } from 'd3-scale'
import { forceSimulation, forceLink, forceManyBody, forceCenter } from 'd3-force'
import { select, selectAll, event } from 'd3-selection'
import { drag as d3drag } from 'd3-drag'
import { range } from 'd3-array'
import env from './test'
import nodeGenerator from './node'

import "../main.scss"

const nodes = users.map((username, i) =>
  nodeGenerator({
    beliefs: beliefs[Math.random() * (beliefs.length - 1)],
    id: (i + 1),
    username
  }))

// let's say everyone starts out with between 1 and 5 connections

const randIndexGenerator = (exclude, length) => {
  const used = [exclude]
  return function() {
    let next = 1 + Math.floor(Math.random() * length)
    while(used.find(d => d === next)) {
      next = Math.floor(Math.random() * length)
    }
    used.push(next)
    return next
  }
}

const links = nodes.map((d) => {
  const createIndex = randIndexGenerator(d.id(), nodes.length)
  return range(1 + Math.round(Math.random() * 5)).map(() => {
    return {
      source: d.id(),
      target: createIndex()
    }
  })
}).reduce(helpers.flatten)

let node, link,
  width = 960,
  height = 600
<commit_msg>fixed issue where index could be out of range<commit_after>import helpers from './helpers/helpers'
import { beliefs } from './config'
import { users } from './fixedData'
import { scaleOrdinal, schemeCategory10 } from 'd3-scale'
import { forceSimulation, forceLink, forceManyBody, forceCenter } from 'd3-force'
import { select, selectAll, event } from 'd3-selection'
import { drag as d3drag } from 'd3-drag'
import { range } from 'd3-array'
import env from './test'
import nodeGenerator from './node'

import "../main.scss"

const nodes = users.map((username, i) =>
  nodeGenerator({
    beliefs: beliefs[Math.random() * (beliefs.length - 1)],
    id: (i + 1),
    username
  }))

// let's say everyone starts out with between 1 and 5 connections

const randIndexGenerator = (exclude, length) => {
  const used = [ exclude ]
  return function() { // index pushed up by 1
    let next = 1 + Math.floor(Math.random() * length)
    while(used.find(d => d === next)) {
      next = 1 + Math.floor(Math.random() * length)
    }
    used.push(next)
    return next
  }
}

const links = nodes.map((d) => {
  const createIndex = randIndexGenerator(d.id(), nodes.length)
  return range(1 + Math.round(Math.random() * 5)).map(() => {
    return {
      source: d.id(),
      target: createIndex()
    }
  })
}).reduce(helpers.flatten)

let node, link,
  width = 960,
  height = 600

{'fraction_non_alphanumeric': 0.15111940298507462, 'fraction_numerical': 0.016417910447761194, 'mean_word_length': 3.373572593800979, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '707890', 'n_tokens_mistral': 888, 'n_tokens_neox': 860, 'n_words': 256}