Search Results

Search found 10523 results on 421 pages for 'generator functions'.

Page 1/421 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Generate a Strong Password using Mac OS X Lion’s Built-in Utility

    - by Usman
    You might’ve heard of the LinkedIn and last.fm security breaches that took place recently. Not to mention the thousands of websites that have been hacked till now. Nothing is invulnerable to hacking. And when something like that happens, passwords are leaked. Choosing a good password is essential. A good password generator can give you the best blend of alphanumeric and symbolic characters, making up a strong password. There are a variety of password generators out there, but not many people know that there’s one built right into Mac OS X Lion. Read on to see how you can generate a strong password without any third party application. To do this, open System Preferences. Click “Users & Groups”. How to Make Your Laptop Choose a Wired Connection Instead of Wireless HTG Explains: What Is Two-Factor Authentication and Should I Be Using It? HTG Explains: What Is Windows RT and What Does It Mean To Me?

    Read the article

  • Extended Events Code Generator v1.001 - A Quick Fix

    - by Adam Machanic
    If you're one of the estimated 3-5 people who've downloaded and are using my XE Code Generator , please note that version 1.000 has a small bug: text data (such as query text) larger than 8000 bytes is truncated. I've fixed this issue and am pleased to present version 1.001, attached to this post. Enjoy, and stay tuned for slightly more interesting enhancements! Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!...(read more)

    Read the article

  • VB.NET - Removing a number from a random number generator

    - by Alex
    I am trying to create a lottery simulator. The lottery has 6 numbers, the number generated must be between 1 - 49 and cannot be in the next number generated. I have tried using the OR function but I'm not entirely sure if I am using it properly. Any help would be great. Thanks. Public Class Form1 Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRun.Click 'Creates a new Random class in VB.NET Dim RandomClass As New Random() '#################################### Dim RandomNumber1 As Integer RandomNumber1 = RandomClass.Next(1, 49) 'Displays first number generated txtFirst.Text = (RandomNumber1) '#################################### Dim RandomNumber2 As Integer RandomNumber2 = RandomClass.Next(1, 49) If RandomNumber2 = RandomNumber1 Then RandomNumber2 = RandomClass.Next(1, 49) End If 'Displays second number generated txtSecond.Text = (RandomNumber2) '#################################### Dim RandomNumber3 As Integer RandomNumber3 = RandomClass.Next(1, 49) If RandomNumber3 = RandomNumber2 Or RandomNumber2 Then RandomNumber3 = RandomClass.Next(1, 49) End If 'Displays third number generated txtThird.Text = (RandomNumber3) '#################################### Dim RandomNumber4 As Integer RandomNumber4 = RandomClass.Next(1, 49) If RandomNumber4 = RandomNumber3 Or RandomNumber2 Or RandomNumber1 Then RandomNumber4 = RandomClass.Next(1, 49) End If 'Displays fourth number generated txtFourth.Text = (RandomNumber4) '#################################### Dim RandomNumber5 As Integer RandomNumber5 = RandomClass.Next(1, 49) If RandomNumber5 = RandomNumber4 Or RandomNumber3 Or RandomNumber2 Or RandomNumber1 Then RandomNumber5 = RandomClass.Next(1, 49) End If 'Displays fifth number generated txtFifth.Text = (RandomNumber5) '#################################### Dim RandomNumber6 As Integer RandomNumber6 = RandomClass.Next(1, 49) If RandomNumber6 = RandomNumber5, RandomNumber4, RandomNumber3, RandomNumber2, RandomNumber1 Then RandomNumber6 = RandomClass.Next(1, 49) End If 'Displays sixth number generated txtSixth.Text = (RandomNumber6) End Sub

    Read the article

  • Functions inside page using Razor View Engine – ASP.NET MVC

    - by hajan
    As we already know, Razor is probably the best view engine for ASP.NET MVC so far. It keeps your code fluid and very expressive. Besides the other functionalities Razor has, it also supports writing local functions. If you want to write a function, you can’t just open new @{ } razor block and write it there… it won’t work. Instead, you should specify @functions { } so that inside the brackets you will write your own C#/VB.NET functions/methods. Lets see an example: 1. I have the following loop that prints data using Razor <ul> @{     int N = 10;     for (int i = 1; i<=N; i++)     {         <li>Number @i</li>     }     } </ul> This code will print the numbers from 1 to 10: Number 1 Number 2 Number 3 Number 4 Number 5 Number 6 Number 7 Number 8 Number 9 Number 10 So, now lets write a function that will check if current number is even, if yes… add Even before Number word. Function in Razor @functions{     public bool isEven(int number)     {         return number % 2 == 0 ? true : false;     } } The modified code which creates unordered list is: <ul> @{     int N = 10;     for (int i = 1; i<=N; i++)     {         if (isEven(@i)) {             <li>Even number @i</li>         }         else {             <li>Number @i</li>         }                 }             } </ul> As you can see, in the modified code we use the isEven(@i) function to check if the current number is even or not… The result is: Number 1 Even number 2 Number 3 Even number 4 Number 5 Even number 6 Number 7 Even number 8 Number 9 Even number 10 So, the main point of this blog was to show how you can define your own functions inside page using Razor View Engine. Of course you can define multiple functions inside the same @functions { } defined razor statement. The complete code: @{     Layout = null; } <!DOCTYPE html> <html> <head>     <title>ASP.NET MVC - Razor View Engine :: Functions</title> </head> <body>     <div>         <ul>         @{             int N = 10;             for (int i = 1; i<=N; i++)             {                 if (isEven(@i)) {                     <li>Even number @i</li>                 }                 else {                     <li>Number @i</li>                 }                         }                     }         </ul>         @functions{             public bool isEven(int number)             {                 return number % 2 == 0 ? true : false;             }         }     </div> </body> </html> Hope you like it. Regards, Hajan

    Read the article

  • Network programming under windows: is WSA functions can be more complete than pSock functions [on hold]

    - by Kane
    I plan to make a set of classic socket functions to simplify their usages. Since i work under windows and linux indifferently i usually make it portable (it's not my first version of this set of functions), but i want to do something different this time and dedicate one version to windows, and one other to linux. With that i wonder for the windows version, if the WSA* functions can have any interest using them instead of the psock ones. I have found nothing about a comparison between them, so if any of you have any idea, suggestion, link or benchmark ?

    Read the article

  • Difference between generator expression and generator function

    - by Neil G
    Is there any difference — performance or otherwise — between generator expressions and generator functions? In [1]: def f(): ...: yield from range(4) ...: In [2]: def g(): ...: return (i for i in range(4)) ...: In [3]: f() Out[3]: <generator object f at 0x109902550> In [4]: list(f()) Out[4]: [0, 1, 2, 3] In [5]: list(g()) Out[5]: [0, 1, 2, 3] In [6]: g() Out[6]: <generator object <genexpr> at 0x1099056e0>

    Read the article

  • ASP.Net How to enforce the HTTP get URL format?

    - by Hamish Grubijan
    [Sorry about a messy question. I believe I am targeting .Net 2.0 (for now)] Hi, I am an ASP.NET noob. For starters I am building a page that parses a URL string and populates a table in a database. I want that string to be strictly of the form: http://<server>:<port>/PageName.aspx?A=1&B=2&C=3&D=4&E=5 The order of the arguments do not matter, I just do not want any of them missing, or any extras. Here is what I tried (yes, it is ugly; I just want to get it to work first): #if (DEBUG) // Maps parameter names to their human readable names. // Used for error checking. private static Dictionary<string, string> paramNameToDisplayName = new Dictionary<string, string> { { A, "a"}, { B, "b"}, { C, "c"}, { D, "d"}, { E, "e"}, { F, "f"}, }; [Conditional("DEBUG")] private void validateRequestParameters(HttpRequest request) { bool endResponse = false; // Use foreach var foreach (string expectedParameterName in paramNameToDisplayName.Keys) { if (request[expectedParameterName] == null) { Response.Write(String.Format("No parameter \"{0}\", aka {1} was passed to the configuration generator. Check your URL string / cookie.", expectedParameterName, paramNameToDisplayName[expectedParameterName])); endResponse = true; } } // Use foreach var foreach (string actualParameterName in request.Params) { if (!paramNameToDisplayName.ContainsKey(actualParameterName)) { Response.Write(String.Format("The parameter \"{0}\", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.", actualParameterName)); endResponse = true; } } if (endResponse) { Response.End(); } } #endif and it works ok, except that it complains about all sorts of other stuff: http://localhost:1796/AddStatusUpdate.aspx?X=0 No parameter "A", aka a was passed to the configuration generator. Check your URL string / cookie.No parameter "B", aka b was passed to the configuration generator. Check your URL string / cookie.No parameter "C", aka c was passed to the configuration generator. Check your URL string / cookie.No parameter "D", aka d was passed to the configuration generator. Check your URL string / cookie.No parameter "E", aka e was passed to the configuration generator. Check your URL string / cookie.No parameter "F", aka f was passed to the configuration generator. Check your URL string / cookie.The parameter "X", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "ASP.NET_SessionId", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "ALL_HTTP", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "ALL_RAW", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "APPL_MD_PATH", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "APPL_PHYSICAL_PATH", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "AUTH_TYPE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "AUTH_USER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "AUTH_PASSWORD", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "LOGON_USER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "REMOTE_USER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_COOKIE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_FLAGS", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_ISSUER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_KEYSIZE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_SECRETKEYSIZE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_SERIALNUMBER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_SERVER_ISSUER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_SERVER_SUBJECT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CERT_SUBJECT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CONTENT_LENGTH", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "CONTENT_TYPE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "GATEWAY_INTERFACE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTPS", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTPS_KEYSIZE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTPS_SECRETKEYSIZE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTPS_SERVER_ISSUER", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTPS_SERVER_SUBJECT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "INSTANCE_ID", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "INSTANCE_META_PATH", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "LOCAL_ADDR", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "PATH_INFO", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "PATH_TRANSLATED", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "QUERY_STRING", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "REMOTE_ADDR", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "REMOTE_HOST", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "REMOTE_PORT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "REQUEST_METHOD", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SCRIPT_NAME", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SERVER_NAME", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SERVER_PORT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SERVER_PORT_SECURE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SERVER_PROTOCOL", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "SERVER_SOFTWARE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "URL", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_CACHE_CONTROL", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_CONNECTION", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_ACCEPT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_ACCEPT_CHARSET", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_ACCEPT_ENCODING", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_ACCEPT_LANGUAGE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_COOKIE", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_HOST", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.The parameter "HTTP_USER_AGENT", was passed to the configuration generator, but it was not expected. Check your URL string / cookie.Thread was being aborted. Is there some way for me to separate the implicit and the explicit parameters, or is it not doable? Should I even bother? Perhaps the philosophy of get is to just throw away that what is not needed. Thanks!

    Read the article

  • helper functions as static functions or procedural functions?

    - by fayer
    i wonder if one should create a helper function in a class as a static function or just have it declared as a procedural function? i tend to think that a static helper function is the right way to go cause then i can see what kind of helper function it is eg. Database::connect(), File::create(). what is best practice?

    Read the article

  • F#: any way to use member functions as unbound functions?

    - by gatoatigrado
    Is there a way to extract member functions, and use them as F# functions? I'd like to be able to write the following: mystring |> string.Split '\n' |> Array.filter (string.Length >> (=) 0 >> not) The code above works if you [let] let mystring = "a c\nb\n" let stringSplit (y:char) (x:string) = x.Split(y) let stringLength (x:string) = x.Length mystring |> stringSplit '\n' |> Array.filter (stringLength >> (=) 0 >> not)

    Read the article

  • Python — Time complexity of built-in functions versus manually-built functions in finite fields

    - by stackuser
    Generally, I'm wondering about the advantages versus disadvantages of using the built-in arithmetic functions versus rolling your own in Python. Specifically, I'm taking in GF(2) finite field polynomials in string format, converting to base 2 values, performing arithmetic, then output back into polynomials as string format. So a small example of this is in multiplication: Rolling my own: def multiply(a,b): bitsa = reversed("{0:b}".format(a)) g = [(b<<i)*int(bit) for i,bit in enumerate(bitsa)] return reduce(lambda x,y: x+y,g) Versus the built-in: def multiply(a,b): # a,b are GF(2) polynomials in binary form .... return a*b #returns product of 2 polynomials in gf2 Currently, operations like multiplicative inverse (with for example 20 bit exponents) take a long time to run in my program as it's using all of Python's built-in mathematical operations like // floor division and % modulus, etc. as opposed to making my own division, remainder, etc. I'm wondering how much of a gain in efficiency and performance I can get by building these manually (as shown above). I realize the gains are dependent on how well the manual versions are built, that's not the question. I'd like to find out 'basically' how much advantage there is over the built-in's. So for instance, if multiplication (as in the example above) is well-suited for base 10 (decimal) arithmetic but has to jump through more hoops to change bases to binary and then even more hoops in operating (so it's lower efficiency), that's what I'm wondering. Like, I'm wondering if it's possible to bring the time down significantly by building them myself in ways that maybe some professionals here have already come across.

    Read the article

  • What can procs and lambdas do that functions can't in ruby

    - by SecurityGate
    I've been working in Ruby for the last couple weeks, and I've come to the subject of procs, lambdas and blocks. After reading a fair share of examples from a variety of sources, I don't how they're much different from small, specialized functions. It's entirely possible that the examples I've read aren't showing the power behind procs and lambdas. def zero_function(x) x = x.to_s if x.length == 1 return x = "0" + x else return x end end zero_lambda = lambda {|x| x = x.to_s if x.length == 1 return x = "0" + x else return x end } zero_proc = Proc.new {|x| x = x.to_s if x.length == 1 puts x = "0" + x else puts x end } puts zero_function(4) puts zero_lambda.call(3) zero_proc.call(2) This function, proc, and lambda do the exact same thing, just slightly different. Is there any reason to choose one over another?

    Read the article

  • Non-trivial functions that operate on any monad

    - by Strilanc
    I'm looking for examples of interesting methods that take an arbitrary monad and do something useful with it. Monads are extremely general, so methods that operate on monads are widely applicable. On the other hand, methods I know of that can apply to any monad tend to be... really, really trivial. Barely worth extracting into a function. Here's a really boring example: joinTwice. It just flattens an m m m t into an m t: join n = n >>= id joinTwice n = (join . join) n main = print (joinTwice [[[1],[2, 3]], [[4]]]) -- prints [1,2,3,4] The only non-trivial method for monads that I know of is bindFold (see my answer below). Are there more?

    Read the article

  • Help me find an appropriate ruby/python parser generator

    - by Geo
    The first parser generator I've worked with was Parse::RecDescent, and the guides/tutorials available for it were great, but the most useful feature it has was it's debugging tools, specifically the tracing capabilities ( activated by setting $RD_TRACE to 1 ). I am looking for a parser generator that can help you debug it's rules. The thing is, it has to be written in python or in ruby, and have a verbose mode/trace mode or very helpful debugging techniques. Does anyone know such a parser generator ? EDIT: when I said debugging, I wasn't referring to debugging python or ruby. I was referring to debugging the parser generator, see what it's doing at every step, see every char it's reading, rules it's trying to match. Hope you get the point. BOUNTY EDIT: to win the bounty, please show a parser generator framework, and illustrate some of it's debugging features. I repeat, I'm not interested in pdb, but in parser's debugging framework. Also, please don't mention treetop. I'm not interested in it.

    Read the article

  • Functional Methods on Collections

    - by GlenPeterson
    I'm learning Scala and am a little bewildered by all the methods (higher-order functions) available on the collections. Which ones produce more results than the original collection, which ones produce less, and which are most appropriate for a given problem? Though I'm studying Scala, I think this would pertain to most modern functional languages (Clojure, Haskell) and also to Java 8 which introduces these methods on Java collections. Specifically, right now I'm wondering about map with filter vs. fold/reduce. I was delighted that using foldRight() can yield the same result as a map(...).filter(...) with only one traversal of the underlying collection. But a friend pointed out that foldRight() may force sequential processing while map() is friendlier to being processed by multiple processors in parallel. Maybe this is why mapReduce() is so popular? More generally, I'm still sometimes surprised when I chain several of these methods together to get back a List(List()) or to pass a List(List()) and get back just a List(). For instance, when would I use: collection.map(a => a.map(b => ...)) vs. collection.map(a => ...).map(b => ...) The for/yield command does nothing to help this confusion. Am I asking about the difference between a "fold" and "unfold" operation? Am I trying to jam too many questions into one? I think there may be an underlying concept that, if I understood it, might answer all these questions, or at least tie the answers together.

    Read the article

  • What do you think of this generator syntax?

    - by ChaosPandion
    I've been working on an ECMAScript dialect for quite some time now and have reached a point where I am comfortable adding new language features. I would love to hear some thoughts and suggestions on the syntax. Example generator { yield 1; yield 2; yield 3; if (true) { yield break; } yield continue generator { yield 4; yield 5; yield 6; }; } Syntax GeneratorExpression:     generator  {  GeneratorBody  } GeneratorBody:     GeneratorStatementsopt GeneratorStatements:     StatementListopt GeneratorStatement GeneratorStatementsopt GeneratorStatement:     YieldStatement     YieldBreakStatement     YieldContinueStatement YieldStatement:     yield  Expression  ; YieldBreakStatement:     yield  break  ; YieldContinueStatement:     yield  continue  Expression  ; Semantics The YieldBreakStatement allows you to end iteration early. This helps avoid deeply indented code. You'll be able to write something like this: generator { yield something1(); if (condition1 && condition2) yield break; yield something2(); if (condition3 && condition4) yield break; yield something3(); } instead of: generator { yield something1(); if (!condition1 && !condition2) { yield something2(); if (!condition3 && !condition4) { yield something3(); } } } The YieldContinueStatement allows you to combine generators: function generateNumbers(start) { return generator { yield 1 + start; yield 2 + start; yield 3 + start; if (start < 100) { yield continue generateNumbers(start + 1); } }; }

    Read the article

  • How can I build a Truth Table Generator?

    - by KingNestor
    I'm looking to write a Truth Table Generator as a personal project. There are several web-based online ones here and here. (Example screenshot of an existing Truth Table Generator) I have the following questions: How should I go about parsing expressions like: ((P = Q) & (Q = R)) = (P = R) Should I use a parser generator like ANTLr or YACC, or use straight regular expressions? Once I have the expression parsed, how should I go about generating the truth table? Each section of the expression needs to be divided up into its smallest components and re-built from the left side of the table to the right. How would I evaluate something like that? Can anyone provide me with tips concerning the parsing of these arbitrary expressions and eventually evaluating the parsed expression?

    Read the article

  • C# code generator

    - by Neir0
    Can someone recommend a simple c# code generator. I just looking something with methods like: GenClass = CreateNewClass(AccessModifier,Name......) GenClass.Add(new Method(AccessModifier,RetType,Name....){code=@"....."} GenClass.Add(new Property(AccessModifier,Type, Name....) ........... etc and after creating all classes\methods and other members we call Code Generation function(where we can specific some parametrs) Is there such opensource code generator?

    Read the article

  • C-based (SAX style) XML generator recommendations?

    - by Eonil
    I'm making an XML generator library for Objective-C in iPhone. It's pretty big work making fully standard based generator. So I'm finding a well-documented, stable, proven C lib for generating XML document string by commands (or events) like SAX parser. Any recommendations?

    Read the article

  • Parser generator for inline documentation

    - by Leonth
    To have a general-purpose documentation system that can extract inline documentation of multiple languages, a parser for each language is needed. A parser generator (which actually doesn't have to be that complete or efficient) is thus needed. http://antlr.org/ is a nice parser generator that already has a number of grammars for popular languages. Are there better alternatives i.e. simpler ones that support generating parsers for even more languages out-of-the-box?

    Read the article

  • 'javadoc' look-a-like, using parser generator?

    - by wvd
    Hello all, I'm going to create a javadoc look-a-like for the language I'm mainly using, but I was wondering - is it worth to use a parser generator for this? The main idea to use a parser generator was because I could use templates for the HTML code which could be exported then. Also I could also use PDF templates if I need it. Thanks, William v. Doorn

    Read the article

  • C# Random Number Generator getting stuck in a cycle

    - by Jean Azzopardi
    Hi, I am using .NET to create an artificial life program and I am using C#'s pseudo random class defined in a Singleton. The idea is that if I use the same random number generator throughout the application, I could merely save the seed and then reload from the seed to recompute a certain interesting run. public sealed class RandomNumberGenerator : Random { private static readonly RandomNumberGenerator instance = new RandomNumberGenerator(); RandomNumberGenerator() { } public static RandomNumberGenerator Instance { get { return instance; } } } I also wanted a method that could give me two different random numbers. public static Tuple<int, int> TwoDifferentRandomNumbers(this Random rnd, int minValue, int maxValue) { if (minValue >= maxValue) throw new ArgumentOutOfRangeException("maxValue", "maxValue must be greater than minValue"); if (minValue + 1 == maxValue) return Tuple.Create<int, int>(minValue, maxValue); int rnd1 = rnd.Next(minValue, maxValue); int rnd2 = rnd.Next(minValue, maxValue); while (rnd1 == rnd2) { rnd2 = rnd.Next(minValue, maxValue); } return Tuple.Create<int, int>(rnd1, rnd2); } The problem is that sometimes rnd.Next(minValue,maxValuealways returns minValue. If I breakpoint at this point and try creating a double and setting it to rnd.NextDouble(), it returns 0.0. Anyone know why this is happening? I know that it is a pseudo random number generator, but frankly, I hadn't expected it to lock at 0. The random number generator is being accessed from multiple threads... could this be the source of the problem?

    Read the article

  • Why isn't there a typeclass for functions?

    - by Steve314
    I already tried this on Reddit, but there's no sign of a response - maybe it's the wrong place, maybe I'm too impatient. Anyway... In a learning problem I've been messing around with, I realised I needed a typeclass for functions with operations for applying, composing etc. Reasons... It can be convenient to treat a representation of a function as if it were the function itself, so that applying the function implicitly uses an interpreter, and composing functions derives a new description. Once you have a typeclass for functions, you can have derived typeclasses for special kinds of functions - in my case, I want invertible functions. For example, functions that apply integer offsets could be represented by an ADT containing an integer. Applying those functions just means adding the integer. Composition is implemented by adding the wrapped integers. The inverse function has the integer negated. The identity function wraps zero. The constant function cannot be provided because there's no suitable representation for it. Of course it doesn't need to spell things as if it the values were genuine Haskell functions, but once I had the idea, I thought a library like that must already exist and maybe even using the standard spellings. But I can't find such a typeclass in the Haskell library. I found the Data.Function module, but there's no typeclass - just some common functions that are also available from the Prelude. So - why isn't there a typeclass for functions? Is it "just because there isn't" or "because it's not so useful as you think"? Or maybe there's a fundamental problem with the idea? The biggest possible problem I've thought of so far is that function application on actual functions would probably have to be special-cased by the compiler to avoid a looping problem - in order to apply this function I need to apply the function application function, and to do that I need to call the function application function, and to do that...

    Read the article

  • Retrieving related data in the Symfony Admin Generator

    - by bjoern
    I have a problem with the Admin Generator. The Table of Pages have the column sf_guard_user_id. The rest of the table looks as this part of the generator.yml in the line display, list: title: Pages display: [=title, sfGuardUser, views, state, privacy, created_at, updated_at] sort: [created_at, desc] fields: sfGuardUser: { label: Author } created_at: { label: Published, date_format: dd.MM.y } updated_at: { label: Updated, date_format: dd.MM.y } table_method: retrieveUserList Now the sf_guard_user_id is been replaced and the username ist displayed. Don't get me wrong, that works fine. But how can I get other variables from the sfGuarsUser relation? When I only add salt or another variable to display I get this, Unknown record property / related component "salt" on "simplePage" But why?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >