logo
down
shadow

Lottery simulator is returning garbage values and not the users lotto numbers and the winning numbers


Lottery simulator is returning garbage values and not the users lotto numbers and the winning numbers

By : midler
Date : October 23 2020, 06:10 AM
To fix this issue I've been writing this c++ lotto simulator and im trying to get it to display the users lotto numbers (userNums array), the winning numbers that are randomly generated and inserted into an array (pBallDrawing) and then your winnings but when i try to output the two arrays using a for loop i just get garbage values (-84792048 that kind of thing) or the last value of the array. , You're accessing out of range on line 151
code :
    if (userNums[6] == ballDrawing[6])                                 
==27179==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffee1d64a58 at pc 0x00010de9d2ea bp 0x7ffee1d649a0 sp 0x7ffee1d64998
READ of size 4 at 0x7ffee1d64a58 thread T0
    #0 0x10de9d2e9 in matchCounter(int*, int*) deleteme.cpp:151
    #1 0x10de9c863 in main deleteme.cpp:43
    #2 0x7fff6707f014 in start (libdyld.dylib:x86_64+0x1014)

Address 0x7ffee1d64a58 is located in stack of thread T0 at offset 56 in frame
    #0 0x10de9c5ef in main deleteme.cpp:24

  This frame has 3 object(s):
    [32, 56) 'userNums' (line 26) <== Memory access at offset 56 overflows this variable
    [96, 120) 'ballDrawing' (line 27)
    [160, 164) 'num' (line 28)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow deleteme.cpp:151 in matchCounter(int*, int*)
Shadow bytes around the buggy address:
  0x1fffdc3ac8f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac920: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1fffdc3ac940: 00 00 00 00 f1 f1 f1 f1 00 00 00[f2]f2 f2 f2 f2
  0x1fffdc3ac950: 00 00 00 f2 f2 f2 f2 f2 04 f3 f3 f3 00 00 00 00
  0x1fffdc3ac960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1fffdc3ac990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==27179==ABORTING
Abort trap: 6


Share : facebook icon twitter icon
How to pick random numbers from pot with some winning numbers?

How to pick random numbers from pot with some winning numbers?


By : Dan Moran
Date : March 29 2020, 07:55 AM
Hope that helps Revised answer: this example does not require you to store the complete state of the game in a variable; instead, you just need to store the try count and won count:
code :
$won = 0;
for($try = 0; $try < 3; $try++) {
    $slots = array_fill(0, 7 - $try, 0);  // blank slots
    $lucky = array_fill(0, 3 - $won, 1);  // lucky slots
    $pot = array_replace($slots, $lucky); // make some of the slots lucky
    $win = $pot[array_rand($pot)];        // randomly pick a slot
    $won += $win == 1;                    // update won count
    echo sprintf("Try %d: win=%d, total wins=%d\n", $try + 1, $win, $won);
}
$pot = array(               // pot is (an associative) array; 0 = blank, 1 = win
    "pos_1" => 0,
    "pos_2" => 0,
    "pos_3" => 0,
    "pos_4" => 0,
    "pos_5" => 0,
    "pos_6" => 0,
    "pos_7" => 0
);
$win = array_rand($pot, 3); // picks three indexes from the pot randomly
foreach($win as $w) {
    $pot[$w] = 1;           // set winning indicator
}
print_r($pot);
Array
(
    [pos_1] => 0
    [pos_2] => 1
    [pos_3] => 0
    [pos_4] => 1
    [pos_5] => 1
    [pos_6] => 0
    [pos_7] => 0
)
Algorithm is too slow; do I have higher odds of winning the lotto i pick the same 4 numbers

Algorithm is too slow; do I have higher odds of winning the lotto i pick the same 4 numbers


By : Ilia Altshuler
Date : March 29 2020, 07:55 AM
wish of those help The reason of why your code is slow is because in each iteration you are calculating all simulations all over again. In reality you need to check if you won the lottery only once per simulation. So lotto_picks() should probably look something like this:
code :
def lotto_picks ():
  lotto_yr = []

  my_count = 0
  random_count = 0
  for _ in range(iterations):
    new_numbers = lotto()
    lotto_yr.append(new_numbers) # You can still save them for later analysis

    if my_pick == new_numbers:
      my_count = my_count +1

    if random_pick == new_numbers: # Changed from elif to if
      random_count = random_count +1

  print('I have {} % chance of winning if pick the same numbers versus {} % if i picked random numbers. The lotto ran {} times'.format(((my_count/iterations)*100), ((random_count/iterations)*100), iterations))
JS lotto simulator - how to display the established amount of numbers

JS lotto simulator - how to display the established amount of numbers


By : user2500415
Date : March 29 2020, 07:55 AM
With these it helps Here's a JSFiddle - I just sort of guessed at what you're doing.
You had a typo: atempt++.
code :
var attempt = 0;

function losowanie1() {
var available = 6;
var guessed = new Array();

r = new Array(available);

var xd0 = document.getElementById("pole1").value
var xd1 = document.getElementById("pole2").value
var xd2 = document.getElementById("pole3").value
var xd3 = document.getElementById("pole4").value
var xd4 = document.getElementById("pole5").value
var xd5 = document.getElementById("pole6").value

y = new Array(6)
y[0] = xd0
y[1] = xd1
y[2] = xd2
y[3] = xd3
y[4] = xd4
y[5] = xd5

z = new Array(6)



for (var i = 0; i <= available - 1; i++) {
  r[i] = Math.floor((Math.random() * (49 - 1)) + 1);
  if ((y[i] == r[0]) || (y[i] == r[1]) || (y[i] == r[2]) || (y[i] == r[3]) || (y[i] == r[4]) || (y[i] == r[5])) {
    guessed.push(y[i]);
  }



}

attempt++
document.getElementById("wysw").innerHTML = r;
document.getElementById("zatw").innerHTML = guessed;
document.getElementById("zatw2").innerHTML = attempt;
}
Returning garbage numbers and I don't know why

Returning garbage numbers and I don't know why


By : Salman Javeed
Date : March 29 2020, 07:55 AM
like below fixes the issue I'm trying to create a program that reads in numbers from a file into an array, reverse the order of the numbers in the array and then outputs those reversed numbers into a different file. I was able to get the program to work when I already knew how many numbers were in the file but I am having difficulty when I switch my loop to trying to detect the EOF(End of file). When I run this code it will print two of the numbers from the file and the rest are garbage values. Any Help? , There is a bug in the lines:
Python input numbers and select the winning numbers from a predefined list

Python input numbers and select the winning numbers from a predefined list


By : Kuldip Satpute
Date : March 29 2020, 07:55 AM
it fixes the issue I just started learning Python yesterday, it's my first contact with a programming language and I've noticed that I learn better by doing something than by only reading so I'm giving myself different tasks and bash my head until I manage to complete them. Regarding my problem, I'm sure that there's a chance that this question has been asked before, but I can't seem to find it...sorry. So, I want to make a little program that does the following: I have a predefined set of winning lottery numbers. I want the user to input 6 numbers. If all six are winners, the user receives a message like: "You Won!", if only 2 numbers are correct, the message is: "You guessed two numbers", if 3 numbers are correct...etc, you get the point. , You may want to try a more "complex" approach:
Related Posts Related Posts :
  • Compiler error when overriding virtual methods
  • What is the point of function pointers?
  • Which is faster in memory, ints or chars? And file-mapping or chunk reading?
  • ISO file in C++
  • Expected Class-name before { token
  • Can I trust floats or doubles representing integers to retain precision?
  • Qt execute multiple get with QNetworkAccessManager
  • Big and Little endian question
  • Visual Studio 2008 compiles anything in C++ file?
  • C++ pointer to functions, Beginner Question
  • Fastest algorithm for primality test
  • Passing array of pointers to another class
  • Handling macro redefinition without modifying .h files ... C / C++ language
  • Implement SSL with SSPI: How to start?
  • Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)
  • C++ - Unicode Newline
  • Program crashing with 'std::out_of_range' error
  • Use signed or unsigned char in constructing CString?
  • Parallel execution policies in C++ 17
  • C++ Class Templates (Queue of a class)
  • Convert image into useable byte array in C?
  • pointer to preallocated memory as an input parameter and have the function fill it
  • Animated Image in Win32
  • error on compiling statically linked library created in Qt
  • How to easily pass a very long string to a worker process under Windows?
  • Can a class add friend classes at runtime in C++?
  • C++ priority queue in ascending order by specific method for objects
  • Initialize and declare dynamically multiple variables of random entities in a loop in C++
  • Serializing, integer without libaries , getting weird results
  • Function pointers with default parameters in C++
  • Compilation errors with RapidXML
  • Bad_alloc exception when using new for a struct c++
  • count specific things within a code in c++
  • How to extract 48*48 icon image from resource of an executable file?
  • C++ Convert string (or char*) to wstring (or wchar_t*)
  • C++ include .h includes .cpp with same name as well?
  • Any way in C++ to forward declare a function prototype?
  • boost graph adjacency_list, retrieving a node's parents
  • Copy method optimization in compilers
  • what the problem in this program? it doesn't use the second number, and doesn't print the last line?
  • Need to format character precedence in Strings
  • Cross-Platform Camera API
  • sizeof continues to return 4 instead of actual size
  • String search algorithm used by string::find() c++
  • Two-phase lookup: can I avoid "code bloat"?
  • Strongest cipher available to use with C/C++?
  • Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?
  • Firefox XULRunner or TriXul?
  • Does GetSystemInfo (on Windows) always return the number of logical processors?
  • Where is the difference between these code? Shouldn't output be the same?
  • What does it mean mean by "Expected a statement" in C++
  • keybd_event is not working right =(
  • What native C++ profiling tool do you suggest?
  • how to copy char * into a string and vice-versa
  • C++ write to front of file
  • Delphi conversion of C++ header for DVP7010B video card DLL?
  • I keep Getting Control reaches end of non-void function. What am I doing wrong?
  • How to have struct members accessible in different ways
  • Am I abusing Policies?
  • Modern equivalent of BoundsChecker for Visual Studio 2008
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk