![]() | Bovada is the only Internet casino endorsed by the Wizard. Here are my reasons why and my promise of support. |
Random Number Generators
| March 9th, 2011 at 4:01:18 PM permalink | |
| s2dbaker Member since: Jun 10, 2010 Threads: 34 Posts: 1204 | During. Here's the geekery: Update shuffle |
| March 9th, 2011 at 4:12:23 PM permalink | |
| DJTeddyBear Member since: Nov 2, 2009 Threads: 105 Posts: 5682 | Out of curiosity, what language is that? Superstitions are silly, childish, irrational rituals, born out of fear of the unknown.
But how much does it cost to knock on wood? |
| March 9th, 2011 at 4:15:15 PM permalink | |
| MathExtremist Member since: Aug 31, 2010 Threads: 45 Posts: 2511 |
Why are you using integer conversions for the RNG values? With this shuffle algorithm, I don't think you need to convert at all. If you have a table with two columns, A for cards and B for floats, then you just randomly assign the float values in column B, sort on it, and A is now your shuffled deck. On initialization you need to assign 0..51 to column A, but only once (not each time). The only thing you need to do for a new shuffle is re-enter floats for column B and re-sort. Then just use a DB cursor to deal the cards. "In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice."
-- Girolamo Cardano, 1563 |
| March 9th, 2011 at 4:24:18 PM permalink | |
| s2dbaker Member since: Jun 10, 2010 Threads: 34 Posts: 1204 | Microsoft T-SQL Notice too that I have a shuffle number. I can debug if I choose to save the shuffles which comes in handy early in the process. Also, I can have three processors hitting the same table and get 750 hands per second. If you know Microsoft T-SQL, you know that cursors = slow. Avoid at all costs! Once I have the order converted to Integers, I can select directly from the "deck" the card in the 23rd position should I choose to. It leaves me with lots of flexibility. |
| March 9th, 2011 at 7:50:32 PM permalink | |
| MathExtremist Member since: Aug 31, 2010 Threads: 45 Posts: 2511 | I don't know T-SQL specifically; my last real DB work was with Oracle over 7 years ago, but I wasn't ever working iteratively down a table like that. You might want to reconsider doing all this in SQL though. I'm running on a laptop with a low-voltage dual-core 1.3GHz, and I can do about 200,000 shuffles per second using C# code (including the Mersenne Twister as my RNG) and the free MSFT IDE. "In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice."
-- Girolamo Cardano, 1563 |
| March 9th, 2011 at 8:44:57 PM permalink | |
| s2dbaker Member since: Jun 10, 2010 Threads: 34 Posts: 1204 | Nice performance! I could really scramble up some data in a hurry with that. I'll look into it. |
| March 10th, 2011 at 9:25:24 AM permalink | |
| kp Member since: Feb 28, 2011 Threads: 7 Posts: 422 |
That's what I'm thinking. SQL is too slow for this type of thing. But my original quandary was satisfied by using the floats for the sort and then using the rowid for the integer conversion. |
| March 10th, 2011 at 10:21:21 AM permalink | |
| s2dbaker Member since: Jun 10, 2010 Threads: 34 Posts: 1204 | Wow, no love here for the the SQL! I find it to be very flexible. I can make changes to stored procs while processes that use them are running and do a whole lot of programming no-nos in the interest of reduced development time. It's worth the trade-off just so that I don't have to compile :) |
| March 10th, 2011 at 10:31:59 AM permalink | |
| kp Member since: Feb 28, 2011 Threads: 7 Posts: 422 | Don't get me wrong. I love SQL and use it for tasks when I need to manage a lot of data. But you can't beat the speed of in memory processing and low level languages for optimizing tasks with massive repetition. |
| March 10th, 2011 at 2:32:18 PM permalink | |
| MathExtremist Member since: Aug 31, 2010 Threads: 45 Posts: 2511 |
What, are you compiling by hand? :) Seriously, my code is maybe 500 lines long - compiling takes less than a second. Also, the 32-bit version of the Microsoft debugger has an edit-and-continue function where you can change running code without recompiling. Either way, I think you'll find that with a 200x improvement in runtime, it's faster to stop, edit, recompile, and re-run than it is to churn through a sim using random functions in SQL. And that's assuming the RNG built into your database is worth using for Monte Carlo analyses... "In my own case, when it seemed to me after a long illness that death was close at hand, I found no little solace in playing constantly at dice."
-- Girolamo Cardano, 1563 |
![]() | Bovada is the only Internet casino endorsed by the Wizard. Here are my reasons why and my promise of support. |
