{ "id": "62186", "key": "TIMOB-1554", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2012-01-03T10:58:05.000+0000", "created": "2011-04-15T02:55:54.000+0000", "priority": { "name": "Trivial", "id": "5" }, "labels": [ "generate", "ios", "ipad", "iphone", "math", "number", "random" ], "versions": [], "issuelinks": [], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2017-05-30T18:30:18.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

Fix Math.random() so that it actually generates random\nnumber.

\n

Yes, I know you can seed it seconds to make it random, but it\nwould be better to fix it in the core.

\n

Here is the best way, from StackOverflow: \nhttp://stackoverflow.com/questions/160890/generating-random-numbers...

{html}", "attachment": [], "flagged": false, "summary": "iOS - Fix Math.random()", "creator": { "name": "mofle", "key": "mofle", "displayName": "Sindre Sorhus", "active": true, "timeZone": "Europe/Oslo" }, "subtasks": [], "reporter": { "name": "mofle", "key": "mofle", "displayName": "Sindre Sorhus", "active": true, "timeZone": "Europe/Oslo" }, "environment": null, "comment": { "comments": [ { "id": "126022", "author": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I agree. Please add this functionality asap. Thanks\nappcelerator!

{html}", "updateAuthor": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:54.000+0000", "updated": "2011-04-15T02:55:54.000+0000" }, { "id": "126023", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Personally I think the behavior is correct as it is. By not\nmaking the seed automatic it is possible to get reproducible\nresults from the random number generator, which is useful in\ndebugging. Not to mention the fact that this is standard Javascript\nbehavior. I would be more worried if Appcelerator started to modify\nstandard Javascript functions to behave differently.

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:55.000+0000", "updated": "2011-04-15T02:55:55.000+0000" }, { "id": "126024", "author": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I don't want to change Math.random(). I would like a native\nversion with objective-c (and maybe a java version for android).\nThen titanium users could call it with javascript. Maybe it could\nbe added to Titanium.Utils or something similar. The problem I am\nfacing is even though I can get random numbers from javascript,\nthey are the same two to four times in a row. It's actually been a\nshow-stopper for an app that I have about 65% finished. I would\nreally like to build a module that adds this functionality, but I'm\nnot an objective-c programmer.

{html}", "updateAuthor": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:55.000+0000", "updated": "2011-04-15T02:55:55.000+0000" }, { "id": "126025", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

They wouldn't be truly random if they never repeated...

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:56.000+0000", "updated": "2011-04-15T02:55:56.000+0000" }, { "id": "126026", "author": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Yes, but I'm generating numbers between 1 and 9999. If it's\nrandom it should not consistently give me the same numbers over and\nover.

{html}", "updateAuthor": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:56.000+0000", "updated": "2011-04-15T02:55:56.000+0000" }, { "id": "126027", "author": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Paste your code

{html}", "updateAuthor": { "name": "damienelmes", "key": "damienelmes", "displayName": "Damien Elmes", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:56.000+0000", "updated": "2011-04-15T02:55:56.000+0000" }, { "id": "126028", "author": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I've tried several things from appcelerator's q&a site. All\nof them produce similar results. I tried to shorten the code, and\nit seems more and more random the more I remove chunks specific to\nmy app. I'm trying to generate quizzes for an app for students.\nI've created a function that generates a very specific type of\nnumber, and it calls my random function several times. The problem\nI discovered today is, titanium is skipping past my function\nbecause it takes too long. So other parts of my code that require\nthe random number start firing errors because the variable doesn't\nhave a value yet. So, my problem is not entirely with the random\nfunction. However I would still like to see a random number\ngenerator in objective-c that I can access from javascript. I'm\nsorry if I caused confusion.

{html}", "updateAuthor": { "name": "lanceulmer", "key": "lanceulmer", "displayName": "Lance Ulmer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T02:55:56.000+0000", "updated": "2011-04-15T02:55:56.000+0000" }, { "id": "126029", "author": { "name": "rblalock", "key": "rblalock", "displayName": "Rick Blalock", "active": false, "timeZone": "America/Havana" }, "body": "{html}

We have another customer reporting this here: http://developer.appcelerator.com/helpdesk/view/64131#c295801

{html}", "updateAuthor": { "name": "rblalock", "key": "rblalock", "displayName": "Rick Blalock", "active": false, "timeZone": "America/Havana" }, "created": "2011-04-15T02:55:56.000+0000", "updated": "2011-04-15T02:55:56.000+0000" }, { "id": "177766", "author": { "name": "mofle", "key": "mofle", "displayName": "Sindre Sorhus", "active": true, "timeZone": "Europe/Oslo" }, "body": "Any updates?", "updateAuthor": { "name": "mofle", "key": "mofle", "displayName": "Sindre Sorhus", "active": true, "timeZone": "Europe/Oslo" }, "created": "2012-01-02T06:40:49.000+0000", "updated": "2012-01-02T06:40:49.000+0000" }, { "id": "177862", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Sample testing indicates that {{Math.random()}} is seeded from walltime when it's called, which conforms to ECMA-262.15.8.2.1.", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-01-03T10:58:05.000+0000", "updated": "2012-01-03T10:58:05.000+0000" }, { "id": "254831", "author": { "name": "tufosa", "key": "tufosa", "displayName": "Diego Lafuente", "active": true, "timeZone": "Europe/Berlin" }, "body": "Hi,\r\nIt's been a long time since the last comment here, but the bug remains \"Resolved\", but \"Invalid\" (which, to me, is pretty close to \"Unresolved\"). I just performed an experiment that \"proves\" that the performance of Math.random() in Titanium is way behind the one in node or iOS. Here is the detailed description of the experiment: http://developer.appcelerator.com/question/153040/titanium-performance-generating-random-strings. Should I reopen this bug or open a new one?", "updateAuthor": { "name": "tufosa", "key": "tufosa", "displayName": "Diego Lafuente", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-05-30T14:15:01.000+0000", "updated": "2013-05-30T14:15:01.000+0000" } ], "maxResults": 13, "total": 13, "startAt": 0 } } }