Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14083] Math.random() needs to be fixed

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsmath, modules, performance, random, titanium
ReporterCarter Lathrop
AssigneeUnknown
Created2013-05-31T07:17:40.000+0000
Updated2018-02-28T20:03:53.000+0000

Description

*Problem* It seems that the generation of random numbers by Math.random() is not performing well. I've done an experiment where I generate random 8-char strings, and then I check the performance on Titanium, node and native iOS, and the results are quite conclusive. Find a detailed description of the experiment here: http://developer.appcelerator.com/question/153040/titanium-performance-generating-random-strings *Test Case* The experiment I did to test this lack of performance was the following: I coded the same random string generator algorithm in javascript and objC. This is how it looks in javascript: function randomId (length) { var textArray = []; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < length; i++) textArray.push(possible.charAt(Math.floor(Math.random() * possible.length))); return textArray.join(''); } *Results* And then I perform a test where I generate one million of 8-char strings using this algorithm, I store them in an array, and I check for duplicates. The results are: - When I run it with Titanium (iPhone simulator), I get an average of 40 repeated strings. - When I run it with node (same javascript code), I get NO repeated strings. - When I run it with XCode (the objC version of the algorithm) using the iPhone simulator, I get NO repeated strings. *Conclusion* It seems that there is an important lack of performance of the Math.random() method in the Titanium environment.

Comments

  1. Carter Lathrop 2013-05-31

    Diego, Thanks for bringing this to our attention, sorry to hear a similar bug was overlooked in the past. I'll make sure engineering takes a look at this. I know it is a bit much to ask, but for clarity and completeness sake of the ticket would you mind filling out the pertinent information from your post into the description here? It would save a lot of time and we would appreciate the clarity and concise location of all necessary information. Regards, Carter
  2. Diego Lafuente 2013-06-03

    Done!! Please let me know if you need more details about it.
  3. Carter Lathrop 2013-06-03

    Thanks Diego! Great work on this, will pass along to engineering. Best Regards, Carter
  4. Neville Dastur 2015-05-03

    Any news on this?

JSON Source