8000 Randonmess of any() should be improved · Issue #650 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Randonmess of any() should be improved #650

Closed
@jsteemann

Description

@jsteemann

As reported by @ge_o the randomness of db.collection.any() should be improved.

Example:

/* set up a collection with n = 100 values */
db._drop("rand"); 
var c = db._create("rand"); 
var i, n = 100, dist = { }; 

for (i = 0; i < n; ++i) { 
  c.save({ value: i }); 
  dist[i] = 0;
} 

/* get some random values and increase counters */
for (i = 0; i < n * 100; ++i) { 
  dist[c.any().value]++;
} 

/* print results */
dist;

On my machine this returns some very unbalanced distribution, e.g.:

...
  "80" : 82, 
  "81" : 36, 
  "82" : 52, 
  "83" : 75, 
  "84" : 28, 
  "85" : 102, 
  "86" : 54, 
  "87" : 120, 
  "88" : 40, 
  "89" : 61, 
  "90" : 34, 
  "91" : 24, 
  "92" : 172, 
  "93" : 32, 
  "94" : 99, 
  "95" : 268, 
  "96" : 24, 
  "97" : 25, 
  "98" : 36, 
  "99" : 59 

Contrary, generating pseudo-random values with JavaScript Math.random() generates a much more balanced distribution:

...
  "80" : 101, 
  "81" : 95, 
  "82" : 103, 
  "83" : 111, 
  "84" : 86, 
  "85" : 90, 
  "86" : 98, 
  "87" : 104, 
  "88" : 102, 
  "89" : 88, 
  "90" : 103, 
  "91" : 83, 
  "92" : 90, 
  "93" : 86, 
  "94" : 95, 
  "95" : 104, 
  "96" : 99, 
  "97" : 96, 
  "98" : 102, 
  "99" : 88

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0